Ng-click fires twice in response to a single tap

Yep! I encountered the same issue as you (tested with Ionic 1.1.1 to 1.2.4) — logging the event sent two Mouse events at the same coordinates (or offset slightly by 1px)…the only real difference was the timestamp!

To fix in the meantime, I converted all of my “ng-click” to “on-tap” events…now, it’s working flawlessly.

Would love to get a fix (and figure out why this is happening), but this workaround is doing the job in the meantime.

3 Likes

Hey everybody,
I opened an issue here about this: https://github.com/driftyco/ionic/issues/5127

and I made a codePen: http://codepen.io/LouisDoe/pen/gPvGXe?editors=0100 (run it twice to make it work)

Had exactly the same issue. My back button does a save to the database which can take a few seconds. If this happens the back is fired twice. I think it’s related to the fact that the button will be disabled (if you disable a button on the ng-click, the event also fires twice - which is also a bug). The easiest solution for now is to use <a> instead of <button>. I’ve changed all my <button></button> tags to <a></a> tags and the problem is gone.

I’m having the same problem, but changing <button> to <a> doesn’t help.

Is it legit to use on-tap instead of ng-click? It seems to work just fine, are there any drawbacks to this approach?

In the latest version of IONIC, changing <button> to <a> doesn’t work anymore. What I do now is define my own back-button instead of relying on the back-button provided by IONIC and build in logic to ignore the second click:

HTML:

<ion-nav-buttons side="left">
	<a class="button button-clear back-button header-item" ng-click="goBack()">
		<i class="icon ion-ios-arrow-back"></i>&nbsp;Back
	</a>
</ion-nav-buttons>

Controllers.js

$scope.$on('$ionicView.enter', function()
{
	$scope.active = true;
});

$scope.goBack = function()
{
	if ($scope.active)
	{
		$scope.active = false;
		// Do other stuff, like saving data to the database
		$ionicHistory.goBack();
	}
};

Kludgy, but it works.

I had the exact problem as persyval and thanks to him, it’s solved.

Adding data-tap-disabled=“true” to the button helps.

Thanks mate!

it helps !:slight_smile: thanks a lot!