angularjs - ng-repeat指令的 `priority`是什么,你能改变它吗?

标签 angularjs angularjs-directive angularjs-ng-repeat

Angular 文档说:-

The compilation of the DOM is performed by the call to the $compile() method. The method traverses the DOM and matches the directives. If a match is found it is added to the list of directives associated with the given DOM element. Once all directives for a given DOM element have been identified they are sorted by priority and their compile() functions are executed.

我认为 ng-repeat 指令的优先级低于自定义指令,在某些用例中,例如 dynamic id and custom directive 。 Angular 是否允许修改指令的优先级以选择一个指令在另一个指令之前执行?

最佳答案

是的,您可以设置指令的优先级。 ng-repeat 的优先级为 1000 ,实际上比自定义指令要高(默认优先级为0)。您可以使用此数字作为指导,了解如何设置与其相关的指令的优先级。

angular.module('x').directive('customPriority', function() {
    return {
        priority: 1001,
        restrict: 'E',
        compile: function () {
            return function () {...}
        }
    }
})

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. The order of directives with the same priority is undefined. The default priority is 0.

关于angularjs - ng-repeat指令的 `priority`是什么,你能改变它吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19270392/

相关文章:

javascript - 无法读取 AngularJS $resource DELETE 的响应

angularjs-directive - Ng-repeat 在 Sightly 中

javascript - Angular Directive(指令) : communicating values to controller with ampersand methods

angularjs - onFinishRender 没有被触发

javascript - 使用 Angular 翻译在翻译后的字符串中添加 <strong>/粗体文本

javascript - 如果字符串值包含浮点解析并格式化它,否则返回字符串

javascript - 无法读取未定义的属性 '#<Object>' 出现错误?

php - 为什么 ng-repeat 在自动递增 id 时表现得很奇怪?

AngularJS 在 ng-repeat 中设置 ng-click 函数和作用域变量

javascript - Ukit 模态阻止关闭退出按钮