[英]Angular 7 - Nested <ng-template> label doesn't work
I have this code as follow:我有这个代码如下:
<h2>{{ commentTitle }}</h2>
<div *ngIf="errorHappened; then displayError else displayComments">
<div *ngIf="comments == undefined || comments.length == 0; then noComments else commentsList"></div>
</div>
<ng-template #displayError>
<div class="alert alert-danger">An error has occurred. Please try again.</div>
</ng-template>
<ng-template #displayComments>
<ng-template #commentsList>
<ul>
<li *ngFor="let comment of comments">
<div>{{ comment.user }}</div>
<div>{{ comment.date }}</div>
<div>{{ comment.content }}</div>
</li>
</ul>
</ng-template>
<ng-template #noComments>
<div>No comments yet</div>
</ng-template>
</ng-template>
<a class="btn btn-primary" (click)="openDialog()" mat-raised-button type="button">Add new comment</a>
Could anyone help me about why the nested div's after h2 label doesn't work please?任何人都可以帮助我了解为什么 h2 标签后的嵌套 div 不起作用吗?
Thank you in advance.先感谢您。
The solution was as follows:解决方法如下:
<h2>{{ commentTitle }}</h2>
<div *ngIf="errorHappened; then displayError else displayComments"></div>
<ng-template #displayError>
<div class="alert alert-danger">An error has occurred. Please try again.</div>
</ng-template>
<ng-template #displayComments>
<div *ngIf="comments == undefined || comments.length == 0; then noComments else commentsList"></div>
<ng-template #commentsList>
<ul>
<li *ngFor="let comment of comments">
<div>{{ comment.user }}</div>
<div>{{ comment.date }}</div>
<div>{{ comment.content }}</div>
</li>
</ul>
</ng-template>
<ng-template #noComments>
<div>No comments yet</div>
</ng-template>
<a class="btn btn-primary" (click)="openDialog()" mat-raised-button type="button">Add new comment</a>
</ng-template>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.