获取延迟的 Angular 状态? [英] Get state of Angular deferred?

查看:23
本文介绍了获取延迟的 Angular 状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 jQuery deferreds,我曾经能够像这样检查当前状态:

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 deferred, eg 'resolved'

有没有办法对 Angular 延迟做同样的事情?(甚至更好的承诺)

Is there a way to do the same for Angular deferreds? (or even better promises)

推荐答案

更新:

由于 $q 的重构,虽然没有记录,但现在可以实现:

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

原文:

与大多数承诺库(Bluebird、Q、when、RSVP 等)不同,$q 不公开同步检查 API.

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.

您必须在承诺上调用 .then 并且该处理程序中的代码将在承诺履行时运行.

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

这篇关于获取延迟的 Angular 状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆