Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get length of array in ngFor after pipes transformation

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?

like image 770
Scipion Avatar asked Jun 13 '17 12:06

Scipion


2 Answers

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

  • https://github.com/angular/angular/blob/master/packages/common/src/directives/ng_for_of.ts#L15-L17
like image 137
yurzui Avatar answered Sep 28 '22 05:09

yurzui


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

See also https://angular.io/api/common/NgForOf

like image 32
Günter Zöchbauer Avatar answered Sep 28 '22 04:09

Günter Zöchbauer