Angularjs same conflict name directive

There is no question. How do I avoid name clashes when I use external modules. I am currently using the angular bootstrap module, but have loaded another module to use the carousel instead. Both of them have the same carousel directive carousel , and this causes me problems if I include both of these parameters in my module.

 var app = angular.module('text', ['fundoo.directives', 'ui.bootstrap']); 

What would be the best solution for this?

+6
source share
3 answers

In fact, all directives are executed, you can adjust the order of execution using priority paramenter

A priority:

When there are several directives defined for a single DOM element, it is sometimes necessary to specify the order in which the directives are applied. Priority is used to sort directives before calling compilation functions. Priority is defined as a number. First, directives with a high numerical priority are set. Prelink functions are also performed in priority order, but post link functions are performed in reverse order. The order of directives with the same priority is undefined. The default priority is 0.

And you can also tell angular to stop directory digesting in the current element whenever you find a directive with the terminal parameter set to true

https://docs.angularjs.org/api/ng/service/$compile

However, the solution to the problem of creating priorities is a bit more complicated, so I will stick with @nico soluction

and also, here is plunker to verify that angular does both

http://plnkr.co/edit/e66I71UKp5mnurcjVzN4

+5
source

If you have only one name collision between directives, list the module using the carousel that you want to use as the first dependency. From my test, I came to the conclusion that additional directives with the same name are ignored (the first wins).

+1
source

If I were for you , I would use the prefix for my own Angular directives / services / etc, what I have been doing lately and I have no conflict issues.

Alternatively, simply rename the specified directive to something more verbose or specific.

+1
source

All Articles