How to get id when we are click the button

#1

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

Button (click) handler not receiving parameter on Android
#2

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
#3

Thank you so much.its working fine.

#4

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…