管道改造后获取ngFor中的数组长度

Sci*_*ion 11 angular2-pipe angular

我有以下模板:

<div *ngFor="let item of myArray | customPipe1 | customPipe2; let l = length">
  Here is the length of my ngFor : {{l}}
</div>
Run Code Online (Sandbox Code Playgroud)

不幸的是,ngFor中不存在长度.我如何解决这个问题,以便在我的ngFor中提供长度?

yur*_*zui 14

另一种解决方案可能如下

<div *ngFor="let item of myArray | customPipe1 | customPipe2; let l = count">
  Here is the length of my ngFor : {{l}}
</div>
Run Code Online (Sandbox Code Playgroud)

Plunker示例

也可以看看


Gün*_*uer 13

<div *ngFor="let item of myArray | customPipe1 | customPipe2 as result">
  Here is the length of my ngFor : {{result.length}}
</div>
Run Code Online (Sandbox Code Playgroud)

另见https://angular.io/api/common/NgForOf

  • 我怎样才能获得ngFor之外的长度? (3认同)
  • @Luckylooke` {{(myArray | customPipe)?. length}}` (3认同)