atul atul - 2 years ago 49
AngularJS Question

What exact difference is there in 'ng-click' and 'ng-mousedown' events

The line

<div ng-mousedown="count = count + 1" ng-init="count=0">Click me!</div>
means,'Executing an expression when a mouse click occurs.

similarly, the line
<button ng-click="count = count + 1" ng-init="count=0">Click me!</button>
means, 'Increase the count variable by one, each time the button is clicked'

Now what confuses me, is when should i use ng-click and when should i use ng-mousedown?? I mean what exact difference is there between the two?

Answer Source

When should I use them?

You decide, they give you the tools, you build the application with them.

ng-mousedown will trigger whenever any of your mouse buttons is clicked over the element (it doesn't wait till you release the key), this can be used to have custom functionality for in your application depending on your needs (like a menu or zoom effect etc.)

ng-click will trigger when the left mouse button is pressed and released on that element, or when the active element from the keyboard navigation is activated (using tab and tabindex)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download