2017-03-23 6 views
4

우선 순위가 1000 인 사용자 지정 지시문을 만들었습니다. 지시문의 컴파일 함수에서 요소에서 ng-if을 제거합니다. 내 가정은 ng-if은 600의 우선 순위가 낮으므로 컴파일되지 않아야한다는 것입니다.ngif가 우선 순위 레벨을 무시하는 이유는 무엇입니까?

내가 우선 순위에 대한 이해가 정확한지 확인하기 위해 다른 지시를 만든 index.html을

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

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'); 
    } 
    }; 
}); 

app.js. myDirectivemyDirective1을 성공적으로 삭제하지만 ngIf은 삭제하지 못했습니다.

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

답변

2

나는 우선 순위가 그런 식으로 작동하지 않는 이유는 확실하지 않다 : 다음

plunker 링크입니다. 우선 순위가 낮은 지시문을 제거하기 위해 터미널을 사용할 것을 제안 할 수 있습니다. 여기에 Plunker이 업데이트되었습니다.

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

또한 terminal에 대해 이러한 질문을 참조하십시오 답장을

+0

감사합니다. – Vaibhav