gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 23:44:07 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com