2016-11-05 2 views
0

나는 다음과 같은 HTTP GET 요청이 : -http get 요청에 대한 약속을 구현하는 방법은 무엇입니까?

$http({ 
    method: 'GET', 
    url: 'getData.php', 
    params: {bill: 'Active'} 
}) 
.then(function (response) { 
    bill=response.data.results; 
}); 

요청되어 여러 번 모든 HTTP 요청이 완료 될 때까지 처리를 대기 위해 내가 할 수 있습니다. 이를 위해 저는 약속을 구현하고 함수의 끝에서 약속을 되찾고 싶습니다. 이 http get 요청과 관련된 약속을 어떻게 구현할 수 있습니까?

+0

[AngularJS $ q 서비스 API 참조 문서 - $ q.all] (https://docs.angularjs.org/api/ng/service/$q#all)을 참조하십시오. – georgeawg

답변

0
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'} 
}) 
} 
0

요청합니다 (.then(...) 전에 모든) 이미 약속입니다.

Promise.all에 요청 배열을 입력하면 모든 것이 완료되면 완료되는 새로운 약속을 얻습니다.

관련 문제