How to fetch the index number of the clicked row in Ionic 2


I am fetching data from URL in JSON format and have shown it on html. See below image –

enter image description here

I want to click on the name and fetch the array index of the clicked row

How can I do this?

Below is my html code in case you need it:

<ion-row *ngFor = "let list of list"> 
          <ion-col><ion-icon ios="ios-close-circle" md="md-close-circle"></ion-icon></ion-col> 


you need to use index with ngFor

<ion-row ngFor = "let list of list; let i = index;> 
<ion-col (click)="generate(i);">{{list.ID}}</ion-col>

and corresponding ts would be,

generate(index) {
    console.log('index', index);

Answered By – Sajeetharan

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published