我已经构建了一个简单的服务,可以发出多个请求。该服务有两种方法。我无法从服务内部的另一种方法调用一种方法。
Plunkr: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'},
{'url':'data.json','response':'third'},
{'url':'data.json','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;
}])
当我尝试从 startQueue 内部调用 getReport 时出现错误:未定义 getReport。