Why does ngif ignore priority level?

I created a custom directive with a priority of 1000. In the compilation function of the directive, I delete ng-iffrom the element. My guess is that since it ng-ifhas a lower priority of 600, it should not compile.

app.js

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {

});
app.directive('myDirective', function(){
  return {
    priority: 1000,
    compile: function(element){
      angular.element(element).removeAttr('ng-if').removeAttr('my-directive1');
    }
  };
});
app.directive('myDirective1', function(){
  return {
    compile: function(){
      console.log('in mydirective1');
    }
  };
});

index.html

<div my-directive ng-if="false" my-directive1>
  This div should be visible.
</div>

I created another directive to check if my understanding of priority is correct. myDirectivesuccessfully deletes myDirective1, but not ngIf.

Below is a link to plunker:

https://plnkr.co/edit/86mauwbt5I2aV4aoySpz?p=preview

+4
source share
1 answer

, . . Plunker.

app.directive('myDirective', function(){
  return {
    priority: 1000,
    terminal: true,
    compile: function(element){
      //element.removeAttr('ng-if').removeAttr('my-directive1');
    }
  };
});

. terminal:

+2

Source: https://habr.com/ru/post/1672993/


All Articles