If I register two different directives with the same name in two modules, will the last registration win?

In AngularJS, if I register two different directives with the same name in two modules, will the last registration win? IIUC Angular modules provide no namespacing.

Also, do modules in Angular provide anything other than a convenient grouping of configuration of the injector?

Put another way - can you detect at runtime which module something (say a directive) came from?

Edit: re the first part of this question: I think it will. https://docs.angularjs.org/guide/module

Answers:

Answer

AngularJS, if I register two different directives with the same name in two modules, will the last registration win?

It will be a 'tie'. Both of them are registered and both of them are executed. The execution order for directives with the same priority is the same as the order in which they were defined, and link functions will be executed in reverse order.

If they don't meet certain conditions, i.e.

  • Multiple directives requesting isolated scope.
  • Multiple directives publishing a controller under the same name.
  • Multiple directives declared with the transclusion option.
  • Multiple directives attempting to define a template or templateURL.

...then a respective error is thrown. Note that the documentation is inaccurate on 'isolated scope', it is 'new scope' in fact, both simultaneous scope: true and scope: { ... } are prohibited. One scope max per element.

Put another way - can you detect at runtime which module something (say a directive) came from?

No, not without hacking Angular. But multidir error will tell you module names if there are directive collisions.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.