q.all不工作的多个承诺 [英] q.all not working for multiple promises

查看:173
本文介绍了q.all不工作的多个承诺的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下q.all打电话来解析两种承诺。我检查所有的职位,并试图实施q.all的所有其他方式和其相同的情况下

I have the following q.all calling to resolve two promises. I checked all the posts and tried all other ways of implementation q.all and its the same case

var xyzdeffered = $q.defer();
service1.getServiceDetail1($routeParams.id).then(function(promise) {
    xyzdeffered.resolve(promise);
});

var abcdeffered = $q.defer();
service2.getServiceDetail2($routeParams.id).then(function(promise) {
abcdeffered.resolve(promise);
});


$q.all([ xyzdeffered, abcdeffered ]).then(function(data) {

    $scope.variable = data;

});

我期待在q.all变量应该得到填充前两个承诺都解决之后。但不幸的是服务调用本身不会获得数据,并到q.all控制移动返回。我觉得这真是奇怪,因为每个文档,当你的承诺与200响应返回并解决q.all只调用。
我检查分析网络电话,也提出了一些警惕看到code的顺序和发现q.all警报要弹出第一个警报,然后其他的承诺得到解决。
它真的让我气疯为什么一个简单的实现q.all不工作的..
任何帮助将AP preciated。

I am expecting the variable in q.all should get populated only after the first two promises are resolved. But unfortunately the service call itself doesn't get returned with data and the control moves on to the q.all. I find this weird because as per documentation the q.all is called only when your promises are returned with 200 response and are resolved. I checked analysing the network calls and also put some alert to see the sequence of the code and find that the q.all alert is the first alert to be popped up and then the other promises are resolved. Its really making me mad as why a simple implementation of q.all doesnt work.. Any help will be appreciated.

推荐答案

为什么不直接调用第一个承诺$ q.all?

Why not directly call $q.all on first promise ?

$q.all([
    service1.getServiceDetail1($routeParams.id),
    service2.getServiceDetail2($routeParams.id)
]).then(function(data) {
    //Array of result [resultOfgetServiceDetails1, resultOfgetServiceDetails2]
    $scope.variable = data;
});

这篇关于q.all不工作的多个承诺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆