Reputation: 1163
I`m developing an app on ionic 2, but i have an issue with click event.
When I run the app on the device and try to click on a button for example to make an alert, this function fires once, but when I click again the button, the function fires twice.
This is the system information.
Cordova CLI: 6.5.0
Ionic Framework Version: 3.0.1
Ionic CLI Version: 2.2.2
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 1.3.0
ios-deploy version: 1.9.0
ios-sim version: 5.0.8
OS: macOS Sierra
Node Version: v7.2.1
Xcode version: Xcode 8.3.2 Build version 8E2002
And this is the example code:
home.htm
<div padding>
<button ion-button full (click)="TestAlert()">Alert</button>
</div>
home.ts
TestAlert(){
console.log('Hola');
alert('Hola');
}
This is a full example what i`m doing repo
Upvotes: 3
Views: 1835
Reputation: 6421
Try using (tap)
instead of (click)
.
(since you're using ionic-native 3.0.1 there's a change that tap will interfere with the scroll, if this happens you'll need to update to 3.1.1).
Upvotes: 7
Reputation: 708
HTML
<div padding>
<button type="button" class="ion-button full">Alert</button>
</div>
JS
// wait until all dom elements are loaded
$(document).ready(function(){
// init TestAlert as Listener
var TestAlert = function(){
console.log('Hola');
alert('Hola');
}
// bind the click event to the button
$('button').on('click', TestAlert);
});
Upvotes: -3