我创建了一个指令,用于显示另一个指令的示例,该指令作为bootstrap-like documentation page的一部分使用。这是一个例子:
<an-example>
<input ng-model="name" an-spellcheck />
</an-example>
我希望它复制放在其中的标记,并将其放入<code>
标记中,以显示使用该指令所需的标记。
但ng-model
为输入添加了类,使其成为:
<input class="ng-scope ng-pristine" ng-model="name" an-spellcheck />
相反,example
指令应该捕获:
<input ng-model="name" an-spellcheck />
但是,在任何内部指令运行之前,我似乎无法访问被转换的内容。这是a plunker demonstrating the issue。
在controller
,preLink
和postLink
函数中,输入已包含来自ng-model
的css类。
在angular编译子指令之前,有没有办法访问example
指令的内容?
答案 0 :(得分:0)
这是不可能的,因为ngTransclude的优先级为0,而ngModel的优先级为1(编译顺序是从较高的数字到较低的数字)。 因此,将始终首先编译ngModel。可以更改指令的优先级,以便在ngModel之前进行编译,但转换将在以后应用
ngModel优先级: https://docs.angularjs.org/api/ng/directive/ngModel
ngTransclude优先级: https://docs.angularjs.org/api/ng/directive/ngTransclude