【发布时间】:2020-06-04 16:54:05
【问题描述】:
我正在尝试将 ng-template 用于作为单独组件的 html,并且我正在尝试在其他 html 中使用它的引用。这可能吗?如果是这样,我尝试了以下方法并想了解我出了什么问题?
ng-template.html
<ng-template #sample1>
<p>ng template content</p>
</ng-template>
显示模板.html
<div *ngIf="found;">
<ng-container *ngTemplateOutlet="sample1"></ng-container>
</div>
DisplayTemplateComponent.ts
export class DisplayTemplateComponent {
@ViewChild('sample1', {static: false}) sample1: ElementRef;
found = true;
}
【问题讨论】:
标签: angular typescript angular8 angular-directive