How to always run some code when a promise is fulfilled in Angular.js

前端 未结 4 659
囚心锁ツ
囚心锁ツ 2020-12-13 23:17

In my Angular.js application, I\'m running some asynchronous operation. Before it starts I cover the application with a modal div, then once the operation is complete, I nee

4条回答
  •  别那么骄傲
    2020-12-13 23:38

    For those not using angularJS, and if you're ok with catching the error (not sure if .finally() would do that), you could use .catch().then() to avoid the duplicated code.

    Promise.resolve()
      .catch(() => {})
      .then(() => console.log('finally'));
    

    The catch() might end up being useful anyway for logging or other cleanup. https://jsfiddle.net/pointzerotwo/k4rb41a7/

提交回复
热议问题