Get state of Angular deferred?

前端 未结 4 1821
野的像风
野的像风 2020-12-04 19:41

With jQuery deferreds I\'m used to be able to check the current state like this:

var defer = $.Deferred();
defer.state();  //Returns the state of the deferre         


        
4条回答
  •  温柔的废话
    2020-12-04 20:15

    Update:

    Due to refactoring of $q this is now possible although not documented:

    promise.$$state.status === 0 // pending
    promise.$$state.status === 1 // resolved
    promise.$$state.status === 2 // rejected
    

    Original:

    Unlike most promise libraries (Bluebird,Q, when, RSVP etc), $q does not expose a synchronous inspection API.

    There is no way to achieve this from the outside.

    You have to call .then on the promise and code in that handler will run when the promise fulfills.

提交回复
热议问题