I'm using double click functionality in my code. It's working fine in desktop view but the problem is that when I switch to mobile/tablet view double tap doesn't work.
Here's my code sample
HTML:
<a (dblclick)="viewRecord(item.id)">View Record Details</a>
Component:
viewRecord(id) {
this.router.navigate(['course/view/', id]);
}
Any suggestions on how to resolve this problem will be highly appreciated
Usually, "double tap" is not implemented on mobiles like on Desktop... "activated" on single tap. not rerquire sensitivy, since the second tap can occur at amy time. will not feel it familiar on mobile.
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() is an inbuilt method in jQuery which is used to trigger the double-click event to occur. This method occurs when the selected element will be double clicked. Syntax: $(selector).
The ng-dblclick Directive in AngluarJS is used to apply custom behavior when an element is clicked double. It can be used to show or hide some element or it can popup an alert or change the color of text when it is clicked twice.
That is because, there is no dblclick
event registered for mobile devices.
But there is a work around for this. It is kind of a hack. Reference
Instead of listening dblclick
you can listen for normal click
event
<a (click)="viewRecord(item.id)">View Record Details</a>
component file
private touchTime = 0;
viewRecord(id) {
if (this.touchtime == 0) {
// set first click
this.touchtime = new Date().getTime();
} else {
// compare first click to this click and see if they occurred within double click threshold
if (((new Date().getTime()) - this.touchtime) < 800) {
// double click occurred
this.router.navigate(['course/view/', id]);
this.touchtime = 0;
} else {
// not a double click so set as a new first click
this.touchtime = new Date().getTime();
}
}
}
DEMO
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