[英]Using Angular's $q.all with codependent promises
第二個承諾需要第一個承諾的結果作為參數。 我已經看到了使用ES6 Promise解決此問題的示例 。
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類似的行為。 有任何想法嗎?
在Angular 1.4中,您可以使用$q.resolve(result1)
。
資料來源: Angular 1.4 $ q.resolve docs 。
在舊版本中,可以使用$q.defer().resolve(result1)
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.