Length: {{ (list$ | async)?.length }}
@if((list$ | async)?.length > 0){
<ul>
<li *ngFor="let item of (list$ | async)">
{{ item.name }}
</li>
</ul>
}@else {
<span>no data</span>
}
I use Angular 17
, and this solution worked perfectly for me. To check the length of an observable array and handle empty data, I use the async pipe
with the safe navigation operator ?.