How to get id when we are click the button

i want to do that .when i’m click on button i want ot get the button id value how can i do that

below my html button
HTML
<button (click)="find($event)" #button block="" id="test" ion-button>Click</button>
.ts

find(event) {
    alert(event.id);
}

alert showing value is undefined.please help me any one how to fix this issue

Although I don’t think this really belongs on the Ionic Forum but is more of an Angular question and I’m not really sure about why you want to pass an ID on a click event, the answer would be simply to inspect what you exactly pass on with the $event. If you want to get the ID, just alert event.target.id .

Good luck!

1 Like

Thank you so much.its working fine.

For anyone how would (like me) want to try this solution… Don’t.

The problem with this one is that event.target.id depends on where exactly you hit the button. You end up getting different IDs when clicking on the button caption, button background…

It works in a browser but I just spent nearly two days trying to figure out why do I get random results in Cordova…