我在用
角5.2
固定
使用*ngIf isContent else noContent,只有当数据被填充时,我才会尝试呈现一个可观察的结果。逻辑并没有触及else语句。即使在没有数据的情况下,它也在呈现isContent。我已经浏览了这些类似的堆栈溢出问题,看起来我的语法是正确的。我做错了什么?
这是密码。
<ng-container *ngIf="months2025 | async as months; else nocontent">
#### RENDERING REGARDLESS OF MONTHS2025 ####
<div class="column">
<h1>2025</h1> #### <-- THIS SHOWS UP ####
<ul>
<li *ngFor="let month of months">
<a href={{month.url}}> {{ month.fileName }} </a>
</li>
</ul>
</div>
</ng-container>
#### NOT RENDERING WHEN NOCONTENT ####
<ng-template #nocontent>
</ng-template>这是component.ts
export class MinutesComponent {
monthsArray2025: AngularFirestoreCollection<any>;
months2025: Observable<any[]>;
constructor(private afs: AngularFirestore) {
this.monthsArray2025 = afs.collection<any>('minutes', ref => ref.where('year', '==', 2025);
this.months2025 = this.monthsArray2025.valueChanges();
}
}发布于 2018-06-26 01:57:14
因此,有一个关于这个主题的Github问题。目前,我找到的最简单的解决方法是一对*ngIf容器。
<ng-container *ngIf="months2025 | async as months">
<ng-container *ngIf="months.length > 0; else nocontent">
<div class="column">
<li *ngFor="let month of months">
<a href={{month.url}}> {{ month.fileName }} </a>
</li>
</div>
</ng-container>
</ng-container>
<ng-template #nocontent>
</ng-template>https://stackoverflow.com/questions/51026990
复制相似问题