q.all not working for multiple promises

拥有回忆 提交于 2019-12-05 08:03:32

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;
});

You need to reference the promise on the $q.defer() return object:

$q.all([ xyzdeffered.promise, abcdeffered.promise ])
Ahmad Ayyaz

For example you have you run multiple sq-lite queries synchronously just pass the array of queries(you can pass anything) as args into the call of this method.

function methodThatChainsPromises(args,tx) {

    var deferred = $q.defer();

    var chain = args.map(function(arg) {

        var innerDeferred = $q.defer();

        tx.executeSql(arg,[], function(){    
            console.log("Success Query");
            innerDeferred.resolve(true);
        }, function(){
            console.log("Error Query");
            innerDeferred.reject();
        });

        return innerDeferred.promise;
    });

    $q.all(chain).then(
        function(results) {
            deferred.resolve(true)
            console.log("deffered resollve"+JSON.stringify(results));
        }, function(errors) {
              deferred.reject(errors);
              console.log("deffered rejected");
           });
           return deferred.promise;
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!