Search code examples
angulartypescriptnativescriptangular2-nativescript

listview button onclick is not working in angular2 nativescript


I'm performing listview item button onclick. Below is the code I tried so far.When clicking on the button its not triggered console log.

I don't know what was the issue here.

html file:

<ListView [items]="items" class="list-group">

    <ng-template let-item="item">

   <GridLayout  rows="auto" columns="*, auto">

        <Label [nsRouterLink]="['/item', item.id]" [text]="item.name" row="0" col="0" class="list-group-item"> </Label>

        <Button text = "Install" tap ="onTap($event)" row="0" col="1" > </Button>

   </GridLayout>

   </ng-template>
  </ListView>

ts file:

  onTap(args: EventData) : void{
    let button = <Button>args.object;

    console.log("First", "Test");


  })
 }    

Solution

  • Try changing this ...

    <Button text = "Install" tap ="onTap($event)" row="0" col="1" > </Button>
    

    Into this ...

    <Button text = "Install" (tap) ="onTap($event)" row="0" col="1" > </Button>