Я вызываю компонент динамически внутри таблицы. Я использую ViewContainerRef для динамического рендеринга компонента внутри шаблона. Но шаблон, который находится внутри другого элемента, не заполняется. Возможно, потому что при объявлении @ViewChild
другой ng-шаблон отсутствует в DOM.
Вот код компонента:
@ViewChild('loadComponent', {static: false, read: ViewContainerRef}) ref;
ngAfterViewChecked(): void {
const componentFactory =
this._componentFactoryResolver.resolveComponentFactory(DynamicComponent);
const ref = this.ref.createComponent(componentFactory);
ref.changeDetectorRef.detectChanges();
}
Вот код шаблона:
<table>
...
<tr *ngFor="let data of dataItems">
<td *ngIf="data.isDisplay">
<ng-template #loadComponent></ng-template> // this does'nt work
</td>
...
Итак, как мне убедиться, что компонент отображается внутри td
после динамической оценки кода td
?