简体   繁体   中英

Angular - how to check length of Array in *ngFor, when using Async pipe?

I have:

<mat-toolbar-row *ngFor="let idp of Idps | async; last as isLast">

and I need to access the length of it for these:

 <button [disabled]="(Idps| async)?.length===1" [ngClass]="{'disabledBtn': !(Idps | async)?.length > 1}"

this sadly does not work, I managed to make that syntax work only here:

{{ (Idps | async)?.length }}

if I put this in my HTML, it will show on screen the length, but I cannot find the right syntax to use for my [disabled] and [ngClass] tags

Use local variable from NgForOf directive ("count")

<mat-toolbar-row *ngFor="let idp of Idps | async; last as isLast; count as count">

Here you can find all the variables available for NgForOf directive

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM