templateref html内容,angular4中的ElemenetRef和TemplateRef之间的区别

我见过很多ElemenetRef和TemplateRef的例子让我更加困惑.

> ElementRef和TemplateRef之间的区别是什么我们应该使用另一个

this is my element

.ts文件

@ViewChild('element', { read: TemplateRef }) element: TemplateRef;

@ViewChild('template', { read: ViewContainerRef }) template: ViewContainerRef;

ngAfterViewInit() {

this.template.createEmbeddedView(this.element);

}

现在如果我改变上面的代码使用ElementRef,那么它也可以正常工作

@ViewChild('element', { read: ElementRef }) element: ElementRef;

所以我的问题是为什么我应该使用TemplateRef,如果我可以使用ElementRef实现相同的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值