我已经构建了一个提出多个请求的简单服务.该服务有两种方法.我无法在服务中调用另一个方法.
普兰克:http://plnkr.co/edit/2fERik4uTxbxlVOhncMd?p=preview
app.factory('Report',['$http',function($http){ var Authors = { reports : [],requests :[{'url':'data/data.cfm','response':'first'},{'url':'data.json','response':'second'},'response':'third'},'response':'forth'}],getReport : function(target,source,response,callback) { return $http({ url:source,method:"POST",params:{url : target} }).success(function(result) { $scope.progress = response; angular.extend($scope.user,result) console.log($scope.user) } ).error(function(error){ $scope.progress = response }) },startQueue : function (target) { var promises = []; this.requests.forEach(function (obj,i) { console.log(obj.url) promises.push(getReport(target,obj.url,obj.response,function(value){ reports.push(value); console.log(value) })); }); $q.all(promises).then(function () { console.log("Finito"); },function(error){ console.log("errori") }); } }; return Authors; }])
将您的工厂更改为:
app.factory('Report',function($http){ var Authors = { reports : [],}; Authors.getReport = function(target,callback) { }; Authors.startQueue = function (target) { }; return Authors; }])