如何实现http获取请求的承诺?
问题描述:
我有以下的HTTP GET请求: -如何实现http获取请求的承诺?
$http({
method: 'GET',
url: 'getData.php',
params: {bill: 'Active'}
})
.then(function (response) {
bill=response.data.results;
});
的请求进行多次,我想对于处理要等到所有的http请求完成。为此,我想实现承诺,然后在函数结束时返回承诺。我怎样才能实现这个HTTP获取请求的承诺?
答
var arr=[];
arr.push(callHttp());
arr.push(callHttp());
arr.push(callHttp());
promise.all(arr).then(....)
function callHttp(){
return $http({
method: 'GET',
url: 'getData.php',
params: {bill: 'Active'}
})
}
请参阅[AngularJS $ q服务API参考 - $ q.all](https://docs.angularjs.org/api/ng/service/$q#all)。 – georgeawg