0

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

dinup24
  • 1,652
  • 3
  • 16
  • 26

1 Answers1

-2

If they are in different js files, then they will be executed in the order they included in index.html (or landing page).

sam
  • 1,937
  • 1
  • 8
  • 14