Get length of array in ngFor after pipes transformation

Scipion picture Scipion · Jun 13, 2017 · Viewed 29.3k times · Source

I have the following template:

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

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

Answer

yurzui picture yurzui · Jun 13, 2017

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

See also