TemplateRef

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值