0

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>{{list.ID}}</ion-col>
          <ion-col>{{list.PRODUCTSERVICE}}</ion-col> 
          <ion-col>{{list.NAME}}</ion-col>
          <ion-col>{{list.UNIT}}</ion-col>
          <ion-col>{{list.CATEGORY}}</ion-col>
          <ion-col>{{list.HSN}}</ion-col>
          <ion-col>{{list.POSTINGHEAD}}</ion-col>
          <ion-col>{{list.RATE}}</ion-col>
          <ion-col>{{list.TYPE}}</ion-col>
          <ion-col>{{list.SACCODE}}</ion-col>
          <ion-col><ion-icon ios="ios-close-circle" md="md-close-circle"></ion-icon></ion-col> 
       </ion-row> 

3 Answers 3

1

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);
}
5
0

Try like this :

<ion-row *ngFor = "let list of list; let i = index; " (click)="getIndex(i)"></ion-row>

component.ts

getIndex(index) {
    console.log('index', index);
}
1
  • hard to see any difference in answer just elaborating it Oct 30, 2017 at 10:31
-1

Try something like this

*ngFor="let item of items; let i = index"

Now you can pass this index to a click method of every ion-row.

1
  • please shed some light on why the dv ? Oct 30, 2017 at 10:50

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.