Tag: angularjs

在Node.js中发送一个响应给Angular.js

我使用Angular和Node,并且会从GET请求发送一个响应给客户端控制器。 当我使用本地节点而不是Express.js时,用于发送响应的代码行似乎不起作用 这是我的angular度控制器: app.controller('testCtrl', function($scope, $http) { $http.get('/test').then(function(response){ $scope = response.data; }); }); 这本质上是路由到以下服务器脚本: http.createServer(function onRequest(req, res){ if(req.method==='GET'){ var scope = 'this is the test scope'; res.json(scope); // TypeError: res.json is not a function } }).listen(port); 除非使用express服务器,否则res.json()会引发错误 var app = express(); app.all('/*', function(req, res) { if(req.method==='GET'){ var scope = 'this is the test scope'; res.json(scope); […]

通过对象数组循环来提取特定的数据

我正在build立一个节点快速叽叽喳喳状态分析器,我想弄清楚如何拉出tex,并将其分配给一个长string供以后使用。 我试图拉这样的用户状态: client.get('statuses/user_timeline', {params, count:20}, function(error, tweets, response) { var jsonObject; if (!error) { analyze.analyze(tweets); } }); 响应看起来像这样: [ { "coordinates": null, "favorited": false, "truncated": false, "created_at": "Wed Aug 29 17:12:58 +0000 2012", "id_str": "240859602684612608", "entities": { "urls": [ { "expanded_url": "/blog/twitter-certified-products", "url": "", "indices": [ 52, 73 ], "display_url": " } ], "hashtags": [ […]

向本地主机请求远程服务器获取预检请求'Access-Control-Allow-Origin'

完整的错误是这样的: XMLHttpRequest无法加载http:// ip:port / path 。 对预检请求的响应不会通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。 原因' http:// localhost:3000 '因此不被允许访问。 环境细节: 用尽几乎所有的东西,但不能完成任务。 其实我从angular js客户端请求node.js服务器。 我已经尝试了所有可能的select。 stream程就是这样的: 请求从在angularjsdevise的门户网站发起。 在远程机器上点击node.js服务器。 我曾经试过的 expressjs / cors和本地主机NodeJS + Express解决“访问控制允许来源” 客户端代码 $scope.testFunc = function () { $("div#preloader").show(); $http.post(rtcControlUrl, data).success(function () { $("div#preloader").hide(); if(response.success) $.notify(response.msg, "success"); else $.notify(response.msg); console.log(response.data); }).error(function () { $.notify("Request timeout!"); $("div#preloader").hide(); }); }; app.post("/path", cors(), function(req, res) […]

$ q.allPromises返回一个数组,但我只想要一个元素,而不是全部

我在用着 $q.allPromises(http request).then (function (data) { //more code logic }) 它第一次工作,但我24小时后调用这个方法,发现“数据”是一个对象的数组,每当我调用$ q.allPromises与新的http json对象时,它被追加。 我怎么能忘记数组中的旧“对象”。 我每24小时拉一个json,只关心我刚取下的json对象。 我想忽略从前面的http promise请求中拉下来的json对象,但它似乎继续追加到一个数组 我尝试添加 $q.allPromises(http request).then (function (data) { //more code logic data.shift (); }) shift()应该是从数组中删除第一个元素,但它似乎不工作。

angular度$范围数据不会更新

我正在写一个连接到第三方API的应用程序。 api使用auth令牌系统,所以我有一个asynchronous节点js函数,它首先请求令牌,然后使用该令牌来检索一些数据。 问题是,当数据更改angualr $范围不会更新,所以即使在节点js api调用抛出错误页面将显示相同的数据。 通过代码稍微运行一下。 get-salesLead-data.js有一个Async瀑布函数,它首先使用http PUT调用第三方rest api并返回一个auth令牌。 然后将这个令牌传递给Async水的第二个函数,然后使用这个函数进行一个http GET请求来获得销售线索数据。 这里是Node Async API调用。 **get-saleLead-data.js** // app/get-SalesLead-data.js // modules ================================================= var http = require('http'); var express = require('express') var async = require('async'); module.exports = function(app) { Using async to preform async api calls and passing data between them async.waterfall([ // First function is requesting the […]

如何在Html的下拉菜单中访问匹配的数据?

我想从angularjs访问匹配的数据,如: 下面是我想要访问的列表: $scope.orderStatus = [ { os: 'Open', value: 1 }, { os: 'Completed', value: 2 }, { os:'Cancelled',value: 3 }, { os: 'Rejected', value: 4 } ] 下面是访问列表元素。 <tr ng-repeat="order in orders" ng-if="order.OrderStatus==2"> 下面是我的下拉列表。 <div class="tab"> <input type="radio" id="tab-1" name="tab-group-1" checked> <label for="tab-1"> <select style="background: DarkSlateGrey; border-bottom: 2px; border-bottom-width: 4px; border-bottom-style: none; z-index: 2; […]

在不同的控制器文件中使用服务

服务 – optionService.js 控制器 – app.js&welcomeCtrl.js&otherCtrl.js app.js var app = angular.module('mainapp', ['mainapp.welcome','optionServiceModule']); app.controller('mainappCtrl', function ($scope,optionService) { optionService.fetchOptionDetails().success(function(response){ $scope.option = response; }); }); welcomeCtrl.js var app = angular.module('mainapp.welcome', ['optionServiceModule']); app.controller('welcomeCtrl',[function($scope,optionService) { optionService.fetchOptionTwoDetails().success(function(response){ $scope.OptionTwo = response; }); }]); optionService.js var app = angular.module('optionServiceModule',[]); app.factory('optionService',['$http',function($http) { var obj = {}; obj.fetchOptionDetails = function(){ return $http.get('localhost/api/option/optionOne'); } obj.fetchOptionTwoDetails = […]

浏览器的CORS设置 – >网站 – > API服务器

我目前正在运行两个站点,一个基于PHP,一个基于node.js。 node.js版本是API,所以我们称之为“api.com” PHP网站(php.com)是基于HTML / JSangular度的可视网站“php.com”,使用angular度资源POSTs调用“api.com”。 所以一切都很好,直到最近我开始gettting这个错误。 MLHttpRequest cannot load https://api.com/create. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://php.com' is therefore not allowed access. The response had HTTP status code 400. 所以有几件事要注意。 该api.com是从一个https网站,其中PHP是http。 在node.js restify api.com网站,它正在做我认为是必要的CORS支持。 // Allow CORS since other sites may be […]

如何获得数组值和在使用Mongoose结构化?

我正在使用MeanStack AngularJS 。 我将这些值存储到MongoDB中,如下所示: 数据格式 "RoleName" : "Verify", "IsActive" : true, "UIList" : { "UiName": "One", "View" : false, "Edit" : false }, { "UiName": "Two", "View" : false, "Edit" : false }, { "UiName": "Three", "View" : false, "Edit" : false }, { "UiName": "Four", "View" : false, "Edit" : false }, { "UiName": […]

JS错误为:var没有定义。 我如何发送函数的价值

现在我有这个代码来创buildsitemap.xml,当我运行/sitemap.xml database = firebase.database(); var ref = database.ref('urls'); ref.on('value', gotData, errData); function errData(err){ console.log('Error!'); console.log(err); } function gotData(data){ result = data.val() return Object.keys(result) .filter(key => result[key].last_res > 5) .map(key => ({url: '/' + result[key].url_site + '/'})); var urls = gotData(data); } 当我尝试在gotData(数据)函数中运行console.log(url)时,它返回为 { salmon: { count: 1, last_res: 10, url_site: 'salmon' }, 'salmon-food': { count: […]