How to access previous/later elements within an ngFor loop?

You can take advantage of the index property of *ngFor

<div *ngFor="let item of list; let i = index;">
  <div *ngIf="item == list[i-1]"></div>
  <div *ngIf="item == list[0]"></div>
</div>

You can find more info on *ngFor local variables in the docs: https://angular.io/docs/ts/latest/api/common/index/NgFor-directive.html

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)