Angular $ q.all()只传递第一个结果

时间:2013-12-15 10:52:57

标签: http angularjs promise

如标题所述,当我用两个承诺来呼叫$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);     
});

感谢任何帮助。

1 个答案:

答案 0 :(得分:4)

$q.all([resouce1.getAll(), resource2.getAll()]).then(function (res) {
    console.log(res);     
});

all接受promises的数组或散列,然后使用单个数组结果调用函数。

相关问题