In my Angular 2 component I have an Observable array
list$: Observable<any[]>;
In my Template I have
<div *ngIf="list$.length==0">No records found.</div>
<div *ngIf="list$.length>0">
<ul>
<li *ngFor="let item of list$ | async">item.name</li>
</ul>
</div>
But list$.length doesn't work with in case of Observable array.
Update:
It seems that (list$ | async)?.length gives us the length but the below code still doesn't work:
<div>
Length: {{(list$ | async)?.length}}
<div *ngIf="(list$ | async)?.length>0">
<ul>
<li *ngFor="let item of (list$ | async)">
{{item.firstName}}
</li>
</ul>
</div>
</div>
Can anyone please guide how do I check length of Observable array.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…