问题描述
我有两个抽象状态parent
和parent.child
,以及一个可激活状态parent.child.grand
.
I have two abstract states parent
and parent.child
, and an activateable state parent.child.grand
.
我希望 parent
在 parent.child.grand
执行解析之前 承诺解析.为什么?因为parent.grand.child
中需要解析来自parent
的ajax请求中的某个数据.
I want parent
to be promise resolved before parent.child.grand
gets its resolves executed. Why? Because a certain data which comes from the ajax request in the resolve from parent
is required inparent.grand.child
.
这是一个要点
是否可以在不使用控制器的情况下顺序将父状态的承诺链接到子状态?
Is it possible to sequentially chain the promises of parent to children states without using controllers ?
(parent
解析开始-> 完成ajax 请求-> 解析promise -> parent.child.grand
解析开始-> 完成ajax 请求-> 解析promise)
(parent
resolve start -> finish ajax request -> resolve promise -> parent.child.grand
resolve start -> finish ajax request -> resolve promise)
推荐答案
我已经看到了一些关于这个的答案,但如果没有示例,它仍然不完全清楚.文档说:
I've seen a few answers for this but it still wasn't entirely clear without an example. The docs say:
如果你想,必须将解析键注入到子状态中在实例化之前等待承诺得到解决孩子们.
示例如下:
$stateProvider.state('parent', {
resolve:{
resA: function(){
return {'value': 'A'};
}
},
controller: 'parentCtrl'
})
.state('parent.child', {
resolve:{
// Adding resA as an argument here makes it so that this child state's resB resolve
// function is not run until the parent state's resA resolve function is completed.
resB: function(resA){
return {'value': resA.value + 'B'};
}
}
controller: 'childCtrl'
})
而且您不必将 resA 注入子控制器.
And you don't have to inject resA into the child controller.
这篇关于UI-Router:父子状态的顺序解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!