0

I have two modules (A and B) with controllers with the same name. When I import the controllers into module C, the controllers with the same name override each other.

What is the way to avoid this? Naming convention of the type "module.controller" for my controller?

Thanks!

Update

Here is a code example:

module('a',[]).controller("con");
module('b',[]).controller("con");

module('c', ['a','b']) // controller from a overrides controller from b
axsauze
  • 343
  • 4
  • 14
  • Hey @PankajParkar I've added a code example. Does that help? – axsauze Apr 06 '16 at 21:27
  • You shouldn't have two controllers that do the exact same thing. Give them a more descriptive name that distinguishes them from each other. – rgvassar Apr 06 '16 at 22:00
  • 2
    module `c` just combines everything into it's own namespace. all components with the same name will just reference one of them. your best bet is to prefix your controller names lik `aCon` or `bCon`. It' a [known thing](http://stackoverflow.com/questions/17862209/how-to-use-two-angularjs-services-with-same-name-from-different-modules). – Jorg Apr 06 '16 at 22:03

1 Answers1

2

What is the way to avoid this?

Prefix your controller names with something like axs e.g. axsCon.

Note: This is an issue with Angular1 design. Its all global. In fact the directives are all global as well and their names should be prefixed too.

basarat
  • 261,912
  • 58
  • 460
  • 511