class TemplateRef<C> {
get elementRef(): ElementRef
createEmbeddedView(context: C): EmbeddedViewRef<C>
}
官方解释:
Represents an Embedded Template that can be used to instantiate Embedded Views.
代表一个嵌入式模板 可用于实例化嵌入式视图You can access a TemplateRef,in two ways. Via a directive placed on a element (or directive prefixed with *) and have the TemplateRef for this Embedded View injected into the constructor of the directive using the TemplateRef Token. Alternatively you can query for the TemplateRef from a Component or a Directive via Query.
您可以通过两种方式访问TemplateRef。
通过放置在元素(或带前缀*的指令)上的指令,并将该嵌入式视图的TemplateRef注入到使用TemplateRef令牌的指令的构造函数中,或者,您可以通过查询从组件或指令查询TemplateRef。To instantiate Embedded Views based on a Template,use ViewContainerRef,which will create the View and attach it to the View Container.
要实例化基于模板的嵌入式视图,请使用ViewContainerRef,它将创建View并将其附加到View Container。
成员方法
get elementRef(): ElementRef
The location in the View where the Embedded View logically belongs to.
视图中嵌入视图所在的位置。
The data-binding and injection contexts of Embedded Views created from this TemplateRef inherit from the contexts of this location.
嵌入式视图的数据绑定和注入上下文来自该TemplateRef继承的该位置的上下文。通常,新的嵌入式视图附加到此位置的View Container,但在高级用例中,View可以附加到不同的容器,同时保持原始位置的数据绑定和注入上下文。
createEmbeddedView(context: C): EmbeddedViewRef
原文链接:https://www.f2er.com/angularjs/146448.html