【发布时间】:2021-12-22 08:59:16
【问题描述】:
我有以下问题:
在我的 html 中,我有以下代码:
<form-section>
<p>Hello</p>
<form-section>
<ng-template test-template>
TEST
</ng-template>
</form-section>
</form-section>
输出是这样的:
Hello TEST
TEST
但它应该是这样的:
Hello
TEST
在我的form-section-component.html 中,我有以下结构:
<div *ngIf="actionTemplate">
<ng-template [ngTemplateOutlet]="actionTemplate"></ng-template>
</div>
在我的form-section-component.ts:
@ContentChild(TemplateDirective, { read: TemplateRef, static: false }) actionTemplate: TemplateRef<any>;
所以这里的模板应该只在它存在时才显示。但不知何故,我的父组件也显示了模板。即使它没有模板。
【问题讨论】:
标签: angular typescript ng-template