How to get child of tapped item in List View?


#1

When using:

<ListView
  [items]="listData | async"
  (itemTap)="onItemTap($event)">

  <ng-template nsTemplateKey="test" let-item="item">
    <GridLayout rows="auto, auto" columns="*">
      <Label row="0" class="label-1" [text]="item.label_1"></Label>
      <Label row="1" class="label-2" text]="item.label_2"></Label>
    <GridLayout>
  </ng-template>

</ListView>

---

onItemTap(args){
  // ????
}

Any ideas how to figure out which label was tapped?

For example, if the entire item was tapped on first label, how do we get “label-1” reference? Using IDs, # or similar is also acceptable I guess?

I am aware that using (tap) on each label is exactly what I want. But what about performance issues? Would it defeat the point of using List Views?


#2

Aren’t you looking for the args.index by any chance? This will give you the list tap index of each template row.


#3

I wish :slightly_smiling_face:

Surely it should be possible to have multiple tap zones in the same row / item?


#4

If you need to split the taps between the labels then I would go with tap on each, it should be fine for normal length lists. You can also try to name each as #lb1 #lb2 and see if you get them on your main itemTap event - I haven’t tried.