Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS : multiple promise wait all

I have a little question about multiple promise. How can I wait that all promises will be done for return the final result.

See my code :

getInfo : function(){
        return promiseA.then(function(result){
               info  = result;
               //this function have also promises 
               return ServiceA.functionA(info.login)
                      .then(function(favouriteItems){
                          info.favorites = favouriteItems;
                          return $q.when(info);
                       });      
         });       
},

My aims it's to wait the result of ServiceA.functionA before return value.

Thanks

K.L

like image 611
user3108740 Avatar asked Jul 05 '26 05:07

user3108740


2 Answers

I wrote an answer to another question stating the solution to this problem using the $q.all approach.

Check it out: AngularJS: Listen to events, one after the other

like image 177
Sten Muchow Avatar answered Jul 07 '26 01:07

Sten Muchow


You need to use $q.all()

This is a good post here on the question: stackoverflow.com/questions/21310964/angularjs-q-all

like image 39
Sam Avatar answered Jul 06 '26 23:07

Sam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!