本文介绍了如何角$ q.when工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以解释我如何做在AngularJS $ q.when
工作?
我试图分析如何 $ HTTP
工作,并发现这一点:
Can some one explain me how does $q.when
work in AngularJS?I'm trying to analyse how $http
work and found this:
var promise = $q.when(config);
这是从Chrome的控制台配置对象:
And here is config object from Chrome console:
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
接下来会发生什么?如何对象获取的解决或拒绝?
What happens next? How this object get's resolved or rejected?
推荐答案
调用 $ q.when
需要一个承诺或任何其他类型的,如果它不是一个承诺,然后它会在承诺和呼叫决心包裹。如果将值传递给它,然后它是永远不会被拒绝。
Calling $q.when
takes a promise or any other type, if it is not a promise then it will wrap it in a promise and call resolve. If you pass a value to it then it is never going to be rejected.
从文档:
包装一个对象可能是一个值或一个(第三方)当时能承诺到$ Q承诺。当你正在处理的对象可能会或可能不会是一个承诺,或者承诺来自于不可信任的来源,这是很有用的。
这篇关于如何角$ q.when工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!