【发布时间】:2021-11-11 08:48:59
【问题描述】:
我正在创建一个简单的应用程序来使用 observables 测试一些东西,由于某种原因,当我使用 ng-template 标记包装该代码时,HTML 根本不显示。
我在 div 之前使用这个 ng-template 的原因是使用 *ngIf。最初,我认为 *ngIf 是问题所在,但是当我从模板中删除该语句时,它仍然不起作用。所以如果不是问题。
有什么想法吗?
<!-- If I remove the <ng-template> tag, the HTML is rendered, but with it, it doesn't work -->
<ng-template>
<div class="messages-container" *ngIf="(messagesService.errors$ | async) as errors">
<div class="messages" *ngFor="let error of errors">{{error}}</div>
<mat-icon class="close" (click)="onClose()">close</mat-icon>
</div>
</ng-template>
编辑: 当我使用 [ngIf] 而不是 *ngIf 时,它可以工作,但我仍然不明白为什么 [ngIf] 可以工作,以及为什么它不能在没有条件的情况下工作。
【问题讨论】:
标签: angular