簡體   English   中英

$ q.all在angularjs中不起作用

[英]$q.all not working in angularjs

我正在使用angularjs創建項目。 我在用$ q.all調用api時遇到問題,這是我的代碼:

$q.all({
                getCustomerInfo: promocodeService.getCustomerInfo(),
                assCustomerPromoCode: promocodeService.assCustomerPromoCode(),
                getPromocodes:promocodeService.getPromocodes(),
                getAllCurrencies:promocodeService.getAllCurrencies(),
            }).then(function(resolved) {

// here not comes when one of the api is failed

                $rootScope.customerInfo = resolved.getCustomerInfo;
                $scope.assPromoCode = resolved.assCustomerPromoCode;
                $scope.promoCodes = resolved.getPromocodes;
                $scope.getAllCurrencies = resolved.getAllCurrencies;

                });

我的問題是,其中一個api失敗時,它不會進入已解決狀態。

這是預期的行為。 all都旨在在它們全部成功時執行。

您可以根據自己的需要嘗試一些替代方法:

$q.all({
    //...
}).then(function(resolved) {
    //...
}).catch(function() {
    //Do something?
}).finally(function() {
    //Do something?
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM