简体   繁体   中英

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. 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

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

script-ext.js (overriding route config)

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 . Hence I was able successfully override the route config without changing script.js (base code).

But, I am trying to understand how angular determines the order in which config blocks should be run. Could you please help me with this...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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