Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looping using ngFor and skip nth element

Tags:

angular

ngfor

I was wondering if there is a way in angular2 to loop through an array or a list using *ngFor and skip the first or nth element

like image 234
Philip John Avatar asked Feb 21 '17 16:02

Philip John


2 Answers

I just learned from another issue, you can do it with Slice pipe

 *ngFor="let item of items | slice:1;

where 1 is your nth element

https://angular.io/api/common/SlicePipe

see also: Angular start ngFor index from 1

like image 130
Kwoque Avatar answered Sep 20 '22 04:09

Kwoque


<div *ngFor="let item of items; let i=index">
  <div *ngIf="i != n">{{i}} is not n</div>
</div>
like image 37
Günter Zöchbauer Avatar answered Sep 20 '22 04:09

Günter Zöchbauer