Click event not working

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.

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>

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

1 Like

Thank you, it worked.