我见过很多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实现相同的