微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.jb51.cc/angularjs/146153.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐