Tag: angularjs service

似乎无法将数据从一个控制器传递到另一个控制器

问题是,我似乎无法将信息从控制器1发送到控制器2 …我有我的服务,设置/获取数据,但它不工作。 我得到的实际错误是,控制器1的dataService.getData不是一个函数…当它在别处工作。 服务1(在自己的文件中) app.service('dataService', function() { var data, queried; return { setData: function(queryData) { this.data = queryData; this.queried = false; }, getData: function() { this.queried = true; return this.data; } }; }); 控制器1(发送信息) app.controller('MyCtrl', ['$scope', '$location', '$state', function($scope, $location, $state, dataService) { anotherService.functionName(function(err, data) { // do some things here actualService.doesntWork(function(err, data) { if […]

Angular $ http.post和No'Access-Control-Allow-Origin'标题

我有两个应用程序与nodejs和angularjs.nodejs应用程序有这样的一些代码: require('http').createServer(function(req, res) { req.setEncoding('utf8'); var body = ''; var result = ''; req.on('data', function(data) { // console.log("ONDATA"); //var _data = parseInput( data,req.url.toString()); var _data = parseInputForClient(data, req.url.toString()); switch (req.url.toString()) { case "/cubes": { 和这个应用程序主机上的http://localhost:4000 .angularjs应用程序主机与节点http-server模块localhost://www.localhost:3030在我的一个angularjs服务我有这样的事情: fetch:function(){ var data = '{somedata:"somedata"}'; return $http.post('http://localhost:4000/cubes',data).success(function(cubes){ console.log(cubes); }); } 但是当这个服务发送一个请求到服务器得到这个错误: XMLHttpRequest cannot load http://localhost:4000/cubes. No 'Access-Control-Allow-Origin' header is […]