简体   繁体   English

指令的角度优先级不起作用

[英]Angular priority of directives not working

I have this directive that removes unwanted elements from a list, repeated by an ng-repeat . 我有这个指令从列表中删除不需要的元素,由ng-repeat

However i have a hard time getting the priority working, by default i know the ng-repeat that repeats my wanted and unwanted elements is 100, so in my directive i set restriction to a value below that so ensure ng-repeats has finished before looking for unwanted elements. 但是我很难获得优先级工作,默认情况下我知道重复我想要和不需要的元素的ng-repeat是100,所以在我的指令中我将限制设置为低于这个值,所以确保ng-repeats在完成之前已经完成对于不需要的元素

This is (still) not working : 这(仍然)不起作用:

myApp.directive('imageContainerRemoval', function() {
 return {
  priority: 999,
  restrict: 'E',
  link: function postLink (scope, element, attrs) {

From Angular Docs : 来自Angular Docs

Directives with greater numerical priority are compiled first. 首先编译具有更高数字优先级的指令。 Pre-link functions are also run in priority order, but post-link functions are run in reverse order . 预链接功能也按优先级顺序运行, 但后链接功能以相反的顺序运行 The order of directives with the same priority is undefined. 具有相同优先级的指令的顺序是未定义的。 The default priority is 0. 默认优先级为0。

As the link function is just a shortcut for the post-link function, I guess instead you have to use the pre-link function or reverse the priorities. 由于link功能只是post-link功能的快捷方式,我想你必须使用pre-link功能或反转优先级。

NOTE: The priority of ngRepeat is 1000 by default. 注意:默认情况下,ngRepeat的优先级为1000。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM