这里是一个菜鸟问题。使用外部模块时如何避免相同的指令名称冲突。目前我正在使用 angular bootstrap模块,但下载了另一个 module只是从那里使用轮播。它们都有相同的指令名称 carousel
,如果我将它们都包含在我的模块中,它会给我带来问题。
var app = angular.module('text', ['fundoo.directives', 'ui.bootstrap']);
最好的解决方案是什么?
最佳答案
实际上所有指令都会执行,你可以通过priority
参数配置执行顺序
Priority:
When there are multiple directives defined on a single DOM element, sometimes it is necessary to specify the order in which the directives are applied. The priority is used to sort the directives before their compile functions get called. Priority is defined as a number. Directives with greater numerical priority are compiled first. Pre-link functions are also run in priority order, but post-link functions are run in reverse order. The order of directives with the same priority is undefined. The default priority is 0.
而且,只要您发现 terminal
参数设置为 true
https://docs.angularjs.org/api/ng/service/$compile
仍然关于创建优先级的解决方案对问题来说有点复杂,所以我会坚持@nico 的解决方案
还有,这里有一个 plunker 来测试 angular 是否同时执行
关于javascript - angularjs 相同的指令名称冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20546744/