angular 5: templateRef.createEmbeddedView não é uma função
Aqui está o código que estou tentando trabalhar (angular 5):
import { Component, ViewChild, TemplateRef, ViewContainerRef } from '@angular/core';
@Component({
selector: 'vcr',
template: `
<template #tpl>
<h1>ViewContainerRef</h1>
</template>
<div>Some element</div>
<div #container></div>
`,
})
export class VcrCmp {
@ViewChild('container', { read: ViewContainerRef }) _vcr;
@ViewChild('tpl') tpl: TemplateRef<any>;
constructor(
private viewContainerRef: ViewContainerRef
) {
}
ngAfterViewInit() {
console.info(this.viewContainerRef);
console.info(this._vcr);
this._vcr.createEmbeddedView(this.tpl);
this.viewContainerRef.createEmbeddedView(this.tpl);
}
}
O problema é que eu tenho isso (templateRef.createEmbeddedView is not a function
) e realmente não entendo o porquê.
Este código é baseado neste exemplohttps://netbasal.com/angular-2-understanding-viewcontainerref-acc183f3b682 então eu acho que deve funcionar.
O que estou fazendo errado?