How to check the length of an Observable array

Discussão em 'Angular' iniciado por Naveed Ahmed, Abril 24, 2025.

  1. Naveed Ahmed

    Naveed Ahmed Guest

    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.

    Continue reading...

Compartilhe esta Página