javascript Angular js - 解析和 run() 执行顺序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24249081/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Angular js - resolve and run() order of execution
提问by itsme
Thanks to this answer AngularJS app.run() documentation?i can see the order in which modules are ran by Angular, my question is:
感谢这个答案AngularJS app.run() 文档?我可以看到 Angular 运行模块的顺序,我的问题是:
if I have:
如果我有:
app.config(function () {
$routeProvider.when('/', {
....
resolve: {
// something to resolve
}
});
});
app.run(function () {
// something to run
});
Will run()
be executed before the routeProvider resolve:{}
is resolved?
会run()
在routeProviderresolve:{}
解析之前执行吗?
回答by KayakDave
At least in my experiments, yes the resolve is run after app.run
.
至少在我的实验中,是的,解析是在app.run
.
In this jsfiddleyou can see the calling order I got was:
在这个 jsfiddle你可以看到我得到的调用顺序是:
- app config
- app run
- directive setup
- directive compile
- app controller
- directive link
- ** Data resolve called **
- new route's controller
- 应用配置
- 应用程序运行
- 指令设置
- 指令编译
- 应用控制器
- 指令链接
- ** 数据解析调用 **
- 新路由的控制器
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
:
正如您在小提琴中看到的,我通过使用一个console.log
函数作为传递给的对象的属性值来检查这一点resolve
:
resolve: {
data: function() {
console.log('Data resolve called');
}
}
You can use this same approach in your code to check when routeProvider
begins checking the dependencies.
您可以在代码中使用相同的方法来检查何时routeProvider
开始检查依赖项。