【问题标题】:Using Angular's $q.all with codependent promises使用 Angular 的 $q.all 和相互依赖的 Promise
【发布时间】: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 类似的行为。有什么想法吗?

【问题讨论】:

标签: javascript angularjs angular-promise es6-promise


【解决方案1】:

在 Angular 1.4 中,您可以使用 $q.resolve(result1)

来源:Angular 1.4 $q.resolve docs

在旧版本中,您可以使用$q.defer().resolve(result1)

来源:Angular 1.3 Deferred API docs

【讨论】:

    猜你喜欢
    • 2017-11-23
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多