12

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!

1
  • Have you found your answer? I am also looking for the same. Commented May 4, 2016 at 13:50

1 Answer 1

3

Unfortunatelly modules are not namespace mechanism in angularjs. You should come up / follow a naming convention to differentiate the controllers

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.