【发布时间】:2015-08-08 03:41:54
【问题描述】:
第二个promise需要第一个promise的结果作为参数。 我have seen an example 用 ES6 承诺解决了这个问题。
firstThingAsync()
.then(function(result1) {
return Promise.all([Promise.resolve(result1), secondThingAsync(result1)]);
})
.then(function(result1, result2) {
// do something with result1 and result2
})
.catch(function(err){ /* ... */ });
但我不确定哪个 $q 函数具有与 Promise.resolve 类似的行为。有什么想法吗?
【问题讨论】:
-
我之前回答过一个类似的问题:Can this promise nesting be changed to chaining?
标签: javascript angularjs angular-promise es6-promise