角JS - 解析和运行()的执行顺序 [英] Angular js - resolve and run() order of execution

查看:111
本文介绍了角JS - 解析和运行()的执行顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于这个答案 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:


  1. 应用程序配置

  2. 运行应用程序

  3. 指令设置

  4. 指令编译

  5. 应用程序控制器

  6. 指令链接

  7. **名为Data决心**

  8. 新干线的控制器

正如你可以在小提琴看到的,我通过使用的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆