My issue is, the methods used for both the events is getting triggered when I perform "double click"
For example, I need to perform specific functionality when specific event is triggered.
<a (click)="method1()" (dblclick)="method2()">
Both method1()
and method2()
are getting triggered when I perform "double click".
on('click',function(e){ if(e. originalEvent. detail > 1){ return; /* if you are returning a value from this function then return false or cancel the event some other way */ } }); Done.
AngularJS ng-dblclick Directive The ng-dblclick directive tells AngularJS what to do when an HTML element is double-clicked. The ng-dblclick directive from AngularJS will not override the element's original ondblclick event, both are executed.
The dblclick event generates an event on double click the element. The event fires when an element is clicked twice in a very short span of time. We can also use the JavaScript's addEventListener() method to fire the double click event. In HTML, we can use the ondblclick attribute to create a double click event.
You can use a timeout and a boolean flag to solve this. Consider the following:
The DOM takes a few milliseconds to recognize the double click.
But it's damn sure that it recognize the double click but the first click is also recognized.
So the logic goes like this.
isSingleClick: Boolean = true; method1CallForClick(){ this.isSingleClick = true; setTimeout(()=>{ if(this.isSingleClick){ doTheStuffHere(); } },250) } method2CallForDblClick(){ this.isSingleClick = false; doTheStuffDblClickHere(); }
Call the method one in the click event of the element and method 2 in the click event of the element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With