javascript - angularjs 相同的指令名称冲突

标签 javascript angularjs

这里是一个菜鸟问题。使用外部模块时如何避免相同的指令名称冲突。目前我正在使用 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

的指令,您也可以告诉 angular 停止当前元素中的指令消化

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

仍然关于创建优先级的解决方案对问题来说有点复杂,所以我会坚持@nico 的解决方案

还有,这里有一个 plunker 来测试 angular 是否同时执行

http://plnkr.co/edit/e66I71UKp5mnurcjVzN4

关于javascript - angularjs 相同的指令名称冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20546744/

相关文章:

javascript - 对象重映射问题 - 属性未定义

javascript - 将 Redux 状态传递给组件时的最佳实践

javascript - AngularJS 中的自定义和标准多个过滤器

javascript - 两个 D3.js 图与 AngularJS 在同一页面中

javascript - IndexedDB 引用错误 : db is not defined

javascript - Opencart 为 opencart 添加产品选项

javascript - angularjs 是否适合大型以数据为中心的企业 Web 应用程序

mysql - 带有 Angular JS 和 MySql 的表在转发器中显示重复的键

angularjs - 使用 Angularjs 强制 "soft"更新字段

javascript - 防止数组项被选择两次