管道转换后在ngFor中获取数组的长度 [英] Get length of array in ngFor after pipes transformation

查看:309
本文介绍了管道转换后在ngFor中获取数组的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下模板:

<div *ngFor="let item of myArray | customPipe1 | customPipe2; let l = length">
  Here is the length of my ngFor : {{l}}
</div>

很遗憾,ngFor中没有长度。我该如何解决这个问题,以使ngFor内部具有可用的长度?

Unfortunately length doesn't exist in ngFor. How can I work around this issue to have the length available inside my ngFor?

推荐答案

另一个解决方案可能是以下

Another solution could be the following

<div *ngFor="let item of myArray | customPipe1 | customPipe2; let l = count">
  Here is the length of my ngFor : {{l}}
</div>

柱塞示例

Plunker Example

另请参见

  • https://github.com/angular/angular/blob/master/packages/common/src/directives/ng_for_of.ts#L15-L17

这篇关于管道转换后在ngFor中获取数组的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆