access to the index of item in *ngFor access to the index of item in *ngFor angular angular

access to the index of item in *ngFor


<li *ngFor="let item of items;let i=index" style="display: inline;">      //<---added let i=index    <div class="col-lg-3 col-md-4 col-xs-6 thumb">       <a class="thumbnail"           [routerLink]="['/single-picture/:comment', {comment:i} ]">      //<-----changed this line            <img  [src]=item.images.low_resolution.url>        </a>    </div>  </li>


Here is the syntax from the documentation:

Syntax

<li *ngFor="let item of items; let i = index">...</li><li template="ngFor let item of items; let i = index">...</li><template ngFor let-item [ngForOf]="items" let-i="index"><li>...</li></template>

Refer to the documentation here

For your case:

<li *ngFor="let item of items;let i=index" style="display: inline;">        <div class="col-lg-3 col-md-4 col-xs-6 thumb">           <a class="thumbnail" [routerLink]="['/single-picture/:comment', {comment:item.index} ]">                <img  [src]=item.images.low_resolution.url>           </a>    </div>       </li>