Angularjs 异步调用延迟和承诺链

Angularjs 异步调用延迟和承诺链,angularjs,asynchronous,promise,angular-promise,deferred,Angularjs,Asynchronous,Promise,Angular Promise,Deferred,我坚持用ashync呼叫链。我试过谷歌,但找不到确切的答案 要求是我有一个方法 callApi(){ I am calling 4 service that all are asynchronous. I want to chain all the asynchronous calls so that I can do defer.resolve only when all request are done } 任何帮助都是巨大的帮助。 提前谢谢。您可以直接

我坚持用ashync呼叫链。我试过谷歌,但找不到确切的答案

要求是我有一个方法

callApi(){
     I am calling 4 service that all are asynchronous.
     I want to chain all the asynchronous calls so that I can do  
     defer.resolve only when all request are done 
}
任何帮助都是巨大的帮助。 提前谢谢。

您可以直接使用。它接受一个承诺数组并返回一个承诺,当该数组中的所有承诺都已解决时,该承诺将得到解决

例如:

function callMultipleServices() {
    return $q.all([
        //Just some random functions returning promises...
        someAsyncService(),
        $http.get('http://google.de'),
        someOtherAsyncService()
    ]) //.then(function(resultArray) { return doSomethingWith(resultArray) }) 
}

返回的承诺将使用一个数组进行解析,该数组包含您传入的承诺的解析值。如果您希望您的承诺返回一个以某种方式从服务结果派生的值,只需添加一个
。然后
,它将获取结果并以某种方式计算您的最终承诺结果(如上面的注释所示)

in.then function()我将如何返回该值。就像我需要写defer.resove(result)@NaushadAhmad Simply
return
it:-)