Muthukumar Marichamy
Muthukumar Marichamy

Reputation: 1214

Nativescript - Angular 4, how to take the selected item's data in itemTap() in listview

Find the below Listview code, where I have written the onItemTap($event) method in (itemTap).

.html

<ListView [items]="customer" (itemTap)="onItemTap($event)" class="list-group">
            <ng-template let-item="item">
                    <StackLayout class="list-group-item">
                            <Label [text]="item.name"></Label>
                            <Label [text]="item.email"></Label>
                            <Label [text]="item.phoneNumber"></Label>
                    </StackLayout>
            </ng-template>
    </ListView>

.ts

onItemTap(args) { 
    console.log(args.data);
    console.log(args.view);
    console.log(args.index);
    console.log(args.object);
 }

How I take the data of item.name / item.email / item.phonenumber when we do tap.

Upvotes: 0

Views: 1030

Answers (1)

JakubP
JakubP

Reputation: 86

You have your answer hidden in your example. You have access to index of the tapped item.

onItemTap(args) {
    console.log(this.customer[args.index].name);
}

Otherwise you can listen to tap events on your item's template - StackLayout.

Upvotes: 2

Related Questions