0

I have an ng-click and ng-dblclick in the same span. Single clicks correctly call the ng-click function, but double clicks are calling both!

Is there a way around that?

I was thinking I could move both click handlers into a single function and delegate based on click count, but I don't see how to get the click count from the event.

Is there any way to get a double click and a single click to call different functions?

I see this was asked before on StackOverflow but the answers are hacky and old, wondering if there is anything built in to AngularJS 1 that lets you inspect the event object?

Victor Grazi
  • 15,563
  • 14
  • 61
  • 94
  • 2
    see this answer http://stackoverflow.com/questions/20444409/handling-ng-click-and-ng-dblclick-on-the-same-element-with-angularjs – Hadi J Feb 10 '17 at 20:36
  • I saw that. Was hoping for a way to inspect the event object – Victor Grazi Feb 10 '17 at 20:40
  • you can pass to your function the event ng-click="someFn($event)". Anyway ng-dblClick works fine. – yBrodsky Feb 10 '17 at 21:10
  • It's really bad UX to have a handler for both. The only case I found it to be OK is where the single click is used to select and double click is used for getting more details. In that case, you can use mousedown for selection and doubleclick for showing details. The problem is that a single click fires twice when you double click. In the case I'm talking about, it's fine to run the handler for mousedown twice – Ruan Mendes Feb 10 '17 at 21:16
  • @yBrodsky in my code, I have an ng-click and an ng-dblclick on the same element. ng-click works fine. However when user double clicks, both the ng-click and the ng-dblclick are being fired. I solved it by using a $timeout hack as mentioned by hadiJz , but I was hoping for a way to inspect the event for the click count instead, but apparently that is not possible – Victor Grazi Feb 12 '17 at 05:25

0 Answers0