Angular $q returning promise multiple $http calls

后端 未结 3 2103
梦毁少年i
梦毁少年i 2021-01-05 07:16

I\'m working on an $http call that loops over each of multiple api\'s and returns all of the data in one object. I usually have the promise ready to resolve when the $http c

3条回答
  •  执念已碎
    2021-01-05 07:52

    You should add a list of promises in $q ( not resolved promises like in your code ) , which is a $promise service

    Example:

    var firstPromise = service1.getMethod1().$promise;
    var secondPromise = service2.getMethod2().$promise;
    $q.all([firstPromise, secondPromise]).then(function(dataList){
         // dataList[0] will be result of `firstPromise`
         // dataList[1] will be result of `secondPromise`
    });
    

提交回复
热议问题