角JS - 解析和运行()的执行顺序 [英] Angular js - resolve and run() order of execution
问题描述
由于这个答案 AngularJS app.run()文档?我可以看到订单在模块由角跑了,我的问题是:
Thanks to this answer AngularJS app.run() documentation? i can see the order in which modules are ran by Angular, my question is:
如果我有:
app.config(function () {
$routeProvider.when('/', {
....
resolve: {
// something to resolve
}
});
});
app.run(function () {
// something to run
});
威尔的run()
的routeProvider 决心之前执行:{}
解析
Will run()
be executed before the routeProvider resolve:{}
is resolved?
推荐答案
至少,是决心在后 app.run
运行。
At least in my experiments, yes the resolve is run after app.run
.
在本的jsfiddle 你可以看到,我得到了调用顺序为:
In this jsfiddle you can see the calling order I got was:
- 应用程序配置
- 运行应用程序
- 指令设置
- 指令编译
- 应用程序控制器
- 指令链接
- **名为Data决心**
- 新干线的控制器
正如你可以在小提琴看到的,我通过使用的console.log
功能交给决心
:
As you can see in the fiddle, I checked this by using a console.log
function as the value of a property of the object handed to resolve
:
resolve: {
data: function() {
console.log('Data resolve called');
}
}
您可以使用同样的方法在code,检查时 routeProvider
开始检查的依赖关系。
You can use this same approach in your code to check when routeProvider
begins checking the dependencies.
这篇关于角JS - 解析和运行()的执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!