简体   繁体   English

角度承诺-一次呼叫错误时$ q

[英]angular promise - $q when error on one of the call

I have an array and I do for loop on the array. 我有一个数组,我在数组上做for循环。 for eeach item - i do rest call and save it in the array restArr; 对于每个项目-我会进行休息电话并将其保存在数组restArr中;

angular.foreach(myItems , function(item){
    var q = $http.get("someHttpCall").succsee(function(){}).error(function(){});

    restArr.push(q);
}

then i use $q 然后我用$ q

$q.all(restArr).then(function(){

    doSomething();

});

Firstly, what happend if one of the call returned with error? 首先,如果一个呼叫返回错误怎么办? And second - there is a way to start again call that return with error? 其次-有一种方法可以重新开始,并返回错误返回?

thanks 谢谢

If one of the promises within a $q.all is rejected, the overall promise is rejected. 如果$q.all一个承诺被拒绝,则整个承诺将被拒绝。 The rejection value is the same as that from the one rejected promise. 拒绝值与一个被拒绝承诺的值相同。

Catch the rejection, then handle your retry logic in the catch handler. 捕获拒绝,然后在捕获处理程序中处理重试逻辑。

$q.all(restArr)
  .then(doSomething)
  .catch(handleError);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM