What is `priority` of ng-repeat directive can you change it?

后端 未结 2 1088
我寻月下人不归
我寻月下人不归 2020-12-01 07:51

Angular Documentation says: -

The compilation of the DOM is performed by the call to the $compile() method. The method traverses the DOM and matches

2条回答
  •  渐次进展
    2020-12-01 08:13

    Yes, you can set the priority of a directive. ng-repeat has a priority of 1000, which is actually higher than custom directives (default priority is 0). You can use this number as a guide for how to set your own priority on your directives in relation to it.

    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.

提交回复
热议问题