Angularjs, expect a nested promise

I have 3 services that return 3 promises, but the third needs data from the second, so I call it in the second. I want to wait until all three promises are resolved, so I implemented it, but it doesn’t work (it waits only for the first and second).

var promise1, promise2, promise3; promise1 = service1(); promise2 = service2(); promise2.then(function (data) { promise3= service3(data); }); $q.all([ promise1, promise2, promise3]).then(function success() { //somehing }); 
+6
source share
2 answers

You can assign a second promise then() callback with a returned promise from the third service.

 var promise1, promise2, promise3; promise1 = service1(); promise2 = service2(); promise3 = promise2.then(function (data) { return service3(data); }); $q.all([ promise1, promise2, promise3]).then(function success() { //somehing }); 
+11
source

Did you try to put your promise 2 inside promise 1, and then put the final decision inside the delegate with the promise?

This is pretty smooth code, and I'm certainly not an expert, but I had to wait to complete all the actions on other calls to the service, and I had to do such things.

0
source

Source: https://habr.com/ru/post/973189/


All Articles