简体   繁体   English

Angular - 当使用异步 pipe 时,如何检查 *ngFor 中的数组长度?

[英]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如果我把它放在我的 HTML 中,它会在屏幕上显示长度,但我找不到用于[disabled][ngClass]标签的正确语法

Use local variable from NgForOf directive ("count")使用 NgForOf 指令中的局部变量(“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在这里你可以找到所有可用于 NgForOf 指令的变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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