Yashua Yashua - 4 months ago 11x
AngularJS Question

Running promises in parallel with Angular 1.x without stop on fail

I am fetching some images using

. I am calling them currently using
however if one call/promise fails they all do. Is there another way I could do this?

$q.all([$http.get('..'),$http.get('..')]).then(function(res) {
// this will never happen if one get fails.


Simple proof of concept using catch()

var req1 =  $http.get('..').catch(function(err){ return err; });
var req2 =  $http.get('..').catch(function(err){ return err; });

$q.all([req1,req2]).then(function(results) {
     var counts = {pass:0, fail:0}
       var type = item.status === 200 ? 'pass':'fail';
     alert('Results status =' + JSON.stringify(counts))

Because you return something from catch it resolves the initial promise and passes that return down the promise chain (to results array in this case) .

The success callback of $q.all().then will fire as a result