Click event not working


#1

I’m trying to call a function on click, but nothing seems to happen. Please check the below code:

    <ion-list inset>
        
        <ion-item *ngFor="let cat of categories" (click)="sample()">
            <ion-avatar item-left>
              <img src="assets/img/{{cat.image}}.png" alt="{{cat.altName}}">
            </ion-avatar>
            <h2>{{cat.name}}</h2>
            <p>{{cat.description}}</p>
        </ion-item>
        
    </ion-list>
</div>

Function:

sample(){
alert();
}

No click event is working.


#2

Check out the documentation for Items. Particularly you should be using a button in this situation with the ion-item attribute set.

Taken from docs:
<button ion-item (click)="buttonClick()"> Button Item </button>


#3

You could also just add the tappable attribute to your ion-items


#4

Thank you, it worked.