angularjs – 什么是ng-repeat指令的“优先级”可以改变它?

前端之家收集整理的这篇文章主要介绍了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.角允许篡改与指令的优先级选择执行一个前另一个?

是的,您可以设置指令的优先级。 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.

原文链接:https://www.f2er.com/angularjs/146153.html

猜你在找的Angularjs相关文章