我是 Angular JS 的新手,我需要知道如何在同一元素上有 2 个或更多指令时首先执行特定指令。 div 标签上的示例指令 directiveone directivetwo direvtivethree
<div>
<div directiveone directivetwo direvtivethree></div>
</div>
但我需要先加载 directivetwo,然后加载 direvtivethree,然后加载 direvtiveone。
请给出你的建议...
最佳答案
您应该使用指令 priority
来确定哪些指令应该首先编译。
var myModule = angular.module(...);
myModule.directive('directiveName', function (injectables) {
return {
restrict: 'A',
template: '<div></div>',
templateUrl: 'directive.html',
replace: false,
priority: 0,
transclude: false,
...
此选项告诉 Angular 按优先级对指令进行排序,因此具有更高优先级的指令将在其他指令之前被编译/链接。
关于javascript - 如果多个指令在 angularjs 中的单个元素上会发生什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35912256/