transclude
– compile the content of the element and make it available to the directive. Typically used with ngTransclude. The advantage of transclusion is that the linking function receives a transclusion function which is pre-bound to the correct scope. In a typical setup the widget creates an isolate scope,but the transclusion is not a child,but a sibling of the isolate scope. This makes it possible for the widget to have private state,and the transclusion to be bound to the parent (pre-isolate) scope.
true
– transclude the content of the directive.
'element'
– transclude the whole element including any directives defined at lower priority.
transclude:true
所以假设你有一个名为my-transclude-true的指令,用transclude:true声明,如下所示:
<div>
<my-transclude-true>
<span>{{ something }}</span>
{{ otherThing }}
</my-transclude-true>
</div>
编译之后和链接之前,这变为:
<div>
<my-transclude-true>
<!-- transcluded -->
</my-transclude-true>
</div>
my-transclude-true的内容(子项),即< span> {{something}}< / span> {{…,被解释并可用于指令.
转录:’元素’
如果你有一个名为my-transclude-element的指令,用transclude:’element’声明,如下所示:
<div>
<my-transclude-element>
<span>{{ something }}</span>
{{ otherThing }}
</my-transclude-element>
</div>
编译之后和链接之前,这变为:
<div>
<!-- transcluded -->
</div>
在这里,整个元素包括其子元素被转换并可用于指令.
链接后会发生什么?
这取决于你的指令,它需要做transclude函数所需的操作. ngRepeat使用transclude:’element’,以便在范围更改时它可以重复整个元素及其子元素.但是,如果您只需要替换标记并希望保留其内容,则可以使用transclude:true和ngTransclude指令来执行此操作.