好吧,假设我有一系列n个XHR请求:
原文链接:https://www.f2er.com/angularjs/142389.htmlvar promises = []; var AllResults = []; $scope.requests = [ { "uri":"http://foo/bar/action1","name":"Action1" },{ "uri":"http://bar/foo/action2","name":"Action2" },{...},{...} ]; var ParseMyResultsArray = function(){ console.log(AllResults); //... }; angular.forEach($scope.requests,function(request){ var promise = $http.get(request.uri); promises.push(promise); }); angular.forEach(promises,function(promise){ promise.then(function(results){ AllResults.push(results); }); }); //Then,when all promise are resolved... ParseMyResultsArray();
如果在不知道请求数组的大小的情况下解析了所有的promises,我怎么能确定调用ParseMyResultsArray()?
谢谢你的帮助!