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'
            }
        }
0

2 Answers 2

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.
}]);
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.