我正在创建一个指令,如果不满足某些条件,它将限制 HTML 访问。不幸的是,在更改和编译内部 HTML 之前调用内部指令时会出现问题。
是否可以从任何外部指令停止嵌套指令执行?
示例(见控制台):http: //jsfiddle.net/xaQzb/14/
HTML:
<div ng-app="testApp">
<outer-element>
<inner-element>
</inner-element>
</outer-element>
</div>
应用程序
angular.module('testApp', []);
var app = angular.module('testApp');
app
.directive('outerElement', ['$compile', function($compile) {
function linker(scope, element) {
element[0].innerHTML = 'Replaced HTML and should not execute anything inside';
$compile(element.contents())(scope);
}
return {
restrict: 'E',
scope: false,
link: linker
}
}]);
app
.directive('innerElement', function() {
function linker(scope, element) {
console.log('Directive has been called');
}
return {
restrict: 'E',
scope: false,
link: linker
}
});