After Angular.js $http request, call complete function regardless of success or failure of promise

前端 未结 3 1308
礼貌的吻别
礼貌的吻别 2021-02-13 18:46

How can I ensure that the complete() function will run regardless of the outcome of the $http call using the promise API provided with Angular.js?

$         


        
3条回答
  •  礼貌的吻别
    2021-02-13 19:27

    It depends on what you would like to do, but for clean-up logic and similar you may also use finally() to run either on fulfillment or rejection of your promise:

    promise.finally(function () {
        // Do something regardless of outcome.
    });
    

    Please note that although finally() is supported by $q (and some other libraries) is not part of the official draft.

提交回复
热议问题