I'm building an application using Angular-UI-Router. I have a top-level Angular module that depends on sub-modules and those sub-modules have controller with the same name as follows:
var moduleA = angular.module('moduleA', []);
moduleA.controller('SameNameCtrl', function () {
// ModuleA SameNameCtrl implementation
});
var moduleB = angular.module('moduleB', []);
moduleB.controller('SameNameCtrl', function () {
// ModuleB SameNameCtrl implementation
});
var app = angular.module('app', ['ui.route', 'moduleA', 'moduleB']);
How do I specify controller in different modules when constructing state with Angular-UI-Router?
$stateProvider
.state('app.stateA', {
url: '/stateA',
templateUrl: 'template-A.html',
controller: ???? // how to specify moduleA SameNameCtrl
})
.state('app.stateB', {
url: '/stateB',
templateUrl: 'template-B.html',
controller: ???? // how to specify moduleB SameNameCtrl
})
Sure, I can assign different controller name for controllers in different module, but I'd like to know if it's possible with controllers having the same name.
Thanks!
Unfortunatelly modules are not namespace mechanism in angularjs. You should come up / follow a naming convention to differentiate the controllers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With