简体   繁体   English

AngularJS:配置块的执行顺序

[英]AngularJS: Order of execution of config blocks

In case, there are multiple config blocks for an angular module, in what order would they get executed? 如果一个角度模块有多个配置块,它们将以什么顺序执行?

In my angularjs application, I am using $routeProvider to configure the routes in the config block. 在我的angularjs应用程序中,我使用$ routeProvider在config块中配置路由。 Is it possible to override/extend this route configuration in another config block? 是否可以在另一个配置块中覆盖/扩展此路由配置?

In my project, I need enable to customization (eg. overriding route config) that doesn't involve modifying the base code. 在我的项目中,我需要启用不涉及修改基本代码的自定义(例如,覆盖路由配置)。

script.js script.js

var myApp = angular.module("myApp", ['ngRoute']);
myApp.config(['$routeProvider', function ($routeProvider) {
    $routeProvider.
        when('/path1', {
            template: 'path1'
        }
    );
}]);

script-ext.js (overriding route config) script-ext.js (覆盖路由配置)

var myApp = angular.module("myApp");
myApp.config(['$routeProvider', function ($routeProvider) {
    $routeProvider.
        when('/path1', {
            template: 'path1-ext'
        }
    );
}]);

While testing this piece of code, I found that the config block in script.js got executed first and then the config block in script-ext.js . 在测试这段代码时,我发现首先执行script.js中的config块,然后执行script-ext.js中的config块。 Hence I was able successfully override the route config without changing script.js (base code). 因此,我能够成功覆盖路由配置,而无需更改script.js(基本代码)。

But, I am trying to understand how angular determines the order in which config blocks should be run. 但是,我试图了解angular如何确定配置块应运行的顺序。 Could you please help me with this... 你能帮我这个忙吗...

如果它们位于不同的js文件中,则将按照它们在index.html(或登录页面)中包含的顺序执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM