【问题标题】:Angular $q.all() only pass the first result to thenAngular $q.all() 仅将第一个结果传递给 then
【发布时间】:2014-01-02 19:50:01
【问题描述】:

如标题所述,当我用两个承诺调用$q.all() 时,我只收到第一个结果。这就是我正在做的:

$q.all(resouce1.getAll(), resource2.getAll()).then(function (res1, res2) {
    // only output one object which contains the result from the first promise
    // if I swap the two promise, the result is still the first one.
    // can't really get both results at the same time
    console.log(arguments);     
});

感谢任何帮助。

【问题讨论】:

    标签: http angularjs promise


    【解决方案1】:
    $q.all([resouce1.getAll(), resource2.getAll()]).then(function (res) {
        console.log(res);     
    });
    

    all 接受一个数组或 promise 散列,然后调用一个具有单个数组结果的函数。

    【讨论】:

    • :)。惊人的。我错过了传递数组的意义。非常感谢你。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-23
    • 1970-01-01
    • 1970-01-01
    • 2015-08-02
    • 2014-03-05
    • 2015-12-23
    相关资源
    最近更新 更多