Introduction
AngularJS has many built-in directives that are used to specify the event. In this article we will discuss about mouse directives. AngularJS has the following directives to support mouse event.
ngMousedown
The ngMouseDown directive allows us to specify the behavior of element(s) on mousedown event. This directive has highest priority.
Syntax
<ANY ELEMENT ng-mousedown="expression">
...
</ANY ELEMENT>
Example
HTML
- <h4>ngMouseDown Example</h4>
- <div ng-controller="HomeController">
- <button ng-mousedown="count = count + 1" ng-init="count=0">
- Mouse Down
- </button>
- <br /> Count of mouse down on above button: {{count}}
- </div>
Here there is no specific item need to done in controller, hence I have defined blank controller.
- var app = angular.module("app", []);
- app.controller("HomeController", function ($scope) {
- });

ngMouseenter
The ngMouseenter directive allows us to specify the behavior of element(s) on mouse enter event. This directive has highest priority.
Syntax
<ANY ELEMENT ng-mouseenter="expression">
...
</ANY ELEMENT>
Example
HTML
- <h4>ngMouseEnter Example</h4>
- <div ng-controller="HomeController">
- <div style="width:150px;height:50px;background-color:gray" ng-mouseenter="count = count + 1" ng-init="count=0">
- </div>
- <br /> Count of mouse enter on above div object: {{count}}
- </div>
Output

ngMouseleave
The ngMouseleave directive allows us to specify the behavior of element(s) on mouse leave event. This directive has highest priority.
Example
HTML
- <h4>ngMouseLeave Example</h4>
- <div ng-controller="HomeController">
- <div style="width:150px;height:50px;background-color:gray" ng-mouseleave="count = count + 1" ng-init="count=0">
- </div>
- <br /> Count of mouse leave on above div object: {{count}}
- </div>





Santhakumar MunuswamyPosted Dec 23, 2015, 3:33 PM
Thanks for nice article
Raja TPosted Dec 11, 2015, 8:25 AM
Nice, Thanks for sharing
Jaipal ReddyPosted Dec 11, 2015, 7:43 AM
nice share sir.
Harshad PansuriyaPosted Dec 11, 2015, 7:07 AM
Nice one
Ankur MistryPosted Dec 11, 2015, 7:06 AM
good example
Sibeesh VenuPosted Dec 11, 2015, 7:02 AM
Nice Share