angularjs – Angular $q.when如何工作?

前端之家收集整理的这篇文章主要介绍了angularjs – Angular $q.when如何工作?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
可以有人解释我$ q.when如何工作在AngularJS?
我试图分析如何$ http工作,并发现这:
var promise = $q.when(config);

这里是来自Chrome控制台的配置对象:

Object {transformRequest: Array[1],transformResponse: Array[1],cache: Object,method: "GET",url: "/schedule/month_index.html"…}
cache: Object
headers: Object
method: "GET"
transformRequest: Array[1]
transformResponse: Array[1]
url: "/schedule/month_index.html"
__proto__: Object

接下来发生什么?这个对象如何解决或拒绝?

调用$ q.when需要一个promise或任何其他类型,如果它不是一个promise,那么它将它包装在promise和调用resolve。如果你传递一个值给它,那么它永远不会被拒绝。

从文档:

Wraps an object that might be a value or a (3rd party) then-able promise into a $q promise. This is useful when you are dealing with an object that might or might not be a promise,or if the promise comes from a source that can’t be trusted.

原文链接:https://www.f2er.com/angularjs/146774.html

猜你在找的Angularjs相关文章