Button (click) handler not receiving parameter on Android

#1

Now this is a vary strange bug…

Using Ionic serve, everything works well but on Android device (this one has 4.4) the (click) button handler does not receive the event. Well, sometimes it does which makes it even more weird but most of the time, the event is just empty.

HTML:

<button ion-button class="col button" (click)="send($event)" id="b1">1</button>
<button ion-button class="col button" (click)="send($event)" id="b2">2</button>
<button ion-button class="col button" (click)="send($event)" id="b3">3</button>

TS:

send(event){ 
    console.log(event.target.id);
}

Now I am hitting the buttons and the console output from the device looks like:

[app-scripts] [21:16:38] console.log:
[app-scripts] [21:16:46] console.log:
[app-scripts] [21:16:54] console.log:
[app-scripts] [21:16:56] console.log:
[app-scripts] [21:16:57] console.log:
[app-scripts] [21:16:57] console.log:
[app-scripts] [21:16:58] console.log:
[app-scripts] [21:16:58] console.log: b1
[app-scripts] [21:16:58] console.log:
[app-scripts] [21:16:59] console.log: b1
[app-scripts] [21:17:02] console.log:
[app-scripts] [21:17:02] console.log:
[app-scripts] [21:17:03] console.log: b3
[app-scripts] [21:17:04] console.log:
[app-scripts] [21:17:04] console.log: b2
[app-scripts] [21:17:05] console.log: b2
[app-scripts] [21:17:06] console.log:
[app-scripts] [21:17:06] console.log:
[app-scripts] [21:17:07] console.log:
[app-scripts] [21:17:08] console.log:
[app-scripts] [21:17:09] console.log: b1

Weird, isn’t it?

Also it seems to me (but I am not sure) that more quickly I press the buttons one after another, the greater probability that the send function will receive the argument.

//EDIT: Now I have tried also Windows x86 build and it behaves the same. Only it seems to me that it gets the event much more often (30%?). So it seems to be a Cordova issue…

So, any ideas?

#2

OK, I found out that on Cordova, it depends on the area where exactly I push the buttons. This was not at all clear on the touch screen, but I can simulate the same thing on Windows UWP build with mouse.

If I click near the center vertically it does not pass the button event to the handler (although the button is called everytime). If I click near the button top or bottom, it works correctly.

So, I got this idea from here:

But after loosing a day on it… I must say that’s just a bad solution. The target ID depends on the div you click, that means that clicking the caption will actually give you the ID of the caption. Will have to create a separate handler for each button, although the behavior is the same and only takes the ID and does something with it…