0

In the code below for init angular-ui-router,

If I have two modules, both of them have IndexController, which will ui-router use? Can I find a reference to the specify constructor/function of the controller via something like angular.module('targetModule').findController('IndexController')?

state: 'index',
url: '/',
        views: {
            '' : {
                templateUrl: 'index',
                controller: 'IndexController'
            }
        }
garyx
  • 589
  • 5
  • 18

2 Answers2

0

The controller that would be used would be the first one loaded. Once a directive, service, or controller is defined it cannot be overridden by anything else.

At this point in time it is imperative that you avoid name collisions.

Enzey
  • 5,244
  • 1
  • 16
  • 20
0

In angular there is a single $injector handling all resolve requests. My advice would be to just prefix your controllers when registering them. Something like this will avoid name clashes:

var module1 = angular.module('m1', [....]);
var module2 = angular.module('m2', [....]);
module1.controller('m1.IndexController', ['$http', function($http) {
    // do something interesting.
}]);
module2.controller('m2.IndexController', ['$http', function($http) {
    // do something interesting else.
}]);
cleftheris
  • 4,406
  • 37
  • 52