ng-click vs ng-dblclick = ng-click wins every time

10,704 views
Skip to first unread message

Michael Bielski

unread,
Aug 13, 2012, 6:46:30 PM8/13/12
to ang...@googlegroups.com
I think there might be a problem in the event detection for Angular. Look at this fiddle:  http://jsfiddle.net/mbielski/UMrd2/

No matter what you do, the action defined by ng-click always wins. The action defined by ng-dblclick never happens. I really would like to have both on one element, but if I absolutely need to I can go with ng-click only.

Michael Hart / Awesome New Tab Page

unread,
Aug 13, 2012, 7:49:53 PM8/13/12
to ang...@googlegroups.com
Well, you forgot parenthesis for doubleclick. However, because the alert of the first click stops you from doubleclicking, it's impossible on that front also.

Here's with doubleclick working:  http://jsfiddle.net/UMrd2/5/ 

If you want to use both click and doubleclick, you'll need to have a timeout to determine if the click event needs to be cancelled. You have to be careful doing this, though, as if it's too fast/short, users will have trouble double clicking. If it's too slow/long, there'll be a noticeable delay after clicking.


On Monday, August 13, 2012 6:46:30 PM UTC-4, Michael Bielski wrote:
I think there might be a problem in the event detection for Angular. Look at this fiddle:  http://jsfiddle.net/mbielski/UMrd2/

No matter what you do, the action defined by ng-click always wins. The action defined by ng-dblclick never happens. I really would like to have both on one element, but if I absolutely need to I can go with ng-click only.

On Monday, August 13, 2012 6:46:30 PM UTC-4, Michael Bielski wrote:
I think there might be a problem in the event detection for Angular. Look at this fiddle:  http://jsfiddle.net/mbielski/UMrd2/

No matter what you do, the action defined by ng-click always wins. The action defined by ng-dblclick never happens. I really would like to have both on one element, but if I absolutely need to I can go with ng-click only.

Eddie Huang

unread,
Aug 13, 2012, 7:58:55 PM8/13/12
to ang...@googlegroups.com
ng-dbclick implementation is flawed. Or, it is not advisable to use both click and dbclick without normalizing for browser difference, which Angular doesn't do for you.


The dblclick event is only triggered after this exact series of events:

  • The mouse button is depressed while the pointer is inside the element.
  • The mouse button is released while the pointer is inside the element.
  • The mouse button is depressed again while the pointer is inside the element, within a time window that is system-dependent.
  • The mouse button is released while the pointer is inside the element.

It is inadvisable to bind handlers to both the click and dblclick events for the same element. The sequence of events triggered varies from browser to browser, with some receiving two click events before the dblclick and others only one. Double-click sensitivity (maximum time between clicks that is detected as a double click) can vary by operating system and browser, and is often user-configurable.

Michael Bielski

unread,
Aug 13, 2012, 8:02:57 PM8/13/12
to ang...@googlegroups.com
Ahh... I see what you mean. Removing the alerts certainly changed things! Thanks!

Eddie, thanks for the info, but I have a spec to follow that states that one thing happen on single click, and another thing happen on double click. Lazy users.

Eddie Huang

unread,
Aug 13, 2012, 8:05:32 PM8/13/12
to ang...@googlegroups.com
Yeah, in that case, you need to write a custom directive that does the normalization

Michael Bielski

unread,
Aug 14, 2012, 10:27:56 AM8/14/12
to ang...@googlegroups.com
Very interesting. Thanks!

AngularNewbee

unread,
Sep 11, 2012, 3:11:31 AM9/11/12
to ang...@googlegroups.com
Here is a working jsfiddle that might interest you
http://jsfiddle.net/ZeNVa/ 

Am Dienstag, 14. August 2012 16:27:56 UTC+2 schrieb Michael Bielski:
Very interesting. Thanks!

umair khalid

unread,
Dec 22, 2014, 3:21:02 AM12/22/14
to ang...@googlegroups.com, ipodm...@googlemail.com
#AngularNewbee , i try to use your fiddle but it does not work properly , because at start single click counter work properly but when i double click it once , single click counter stop working.
Reply all
Reply to author
Forward
0 new messages