$ q.all promises将数据从第一个承诺注入第二个承诺

时间:2016-04-25 14:33:10

标签: angularjs promise

我想知道是否可以使用$ q.all:

            var promise1 =   $http({
                method: 'GET',
                url: "https://cubber.zendesk.com/api/v2/organizations/"+id+"/users.json",
                dataType: 'json',
                headers: {'Content-Type': 'application/json',
                'Authorization': 'Bearer '+token}

            })
            var promise2 = $http({
                method: 'GET',
                url: "https://cubber.zendesk.com/api/v2/users/"+idname+"/tickets/requested.json",
                dataType: 'json',
                headers: {'Content-Type': 'application/json',
                'Authorization': 'Bearer '+token}

            });

            $q.all([promise1, promise2]).then(function(data){
                console.log(data[0], data[1]);
            });

如果可以从promise 1中检索数据并注入promise 2的url,然后在同一个数组中检索两个promises的完整数据?

1 个答案:

答案 0 :(得分:2)

例如像这样

lockpath

另请参阅this answer, with many different ways来处理它。

相关问题