admin管理员组文章数量:1290179
I have 3 services that return 3 promises, but the third needs the data from the second, so I call it inside the second. I want to wait for all the three promises to be solved, this is the way that I implemented, but doesn't work (waits only for the first and the 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
});
I have 3 services that return 3 promises, but the third needs the data from the second, so I call it inside the second. I want to wait for all the three promises to be solved, this is the way that I implemented, but doesn't work (waits only for the first and the 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
});
Share
Improve this question
asked Jul 31, 2014 at 18:07
TresTres
5711 gold badge5 silver badges19 bronze badges
2 Answers
Reset to default 18You can assign the second promise's 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
});
Have you tried to nest your promise 2 inside promise 1, and then put your final resolve inside the promise 3 delegate?
That's pretty slick code and I'm certainly no expert, but have had to wait to accomplish things on other service calls and have had to do things like that.
本文标签: javascriptAngularJSwait for a nested promiseStack Overflow
版权声明:本文标题:javascript - Angularjs, wait for a nested promise - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739414288a2162215.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论