MouseEnter vs MouseOver in AngularJs

Rohit picture Rohit · Jan 28, 2015 · Viewed 18k times · Source

I was playing with AngularJS mouse events and got into a problem. I know MouseEnter event is fired when mouse enters container of an element and there after MouseOver is fired for all child elements. Thanks to this animation Visualizing mouse events

However turns out that in my case MouseEnter event is never fired. I am working on Angular PhoneCat application (step-10) and did following modifications:

  1. Controllers.js: Added a method to log mouse events
  2. phone-details.html: Added ng-mouseenter and ng-mouseleave handlers

Result:

Only mouseover and mouseout event being logged

Question:

Is this behavior happening because images are ul element and we are moving mouse in child elements? and How can I get mouseenter event on image?

Thank you enter image description here

Answer

audonex picture audonex · Jan 28, 2015

Angular's ngMouseenter directive fires an event whose type is mouseover, as you can see in this plunker.

The difference from ngMouseover is that it's fired only once - when mouse enters the element, not after every movement within this element too.

<!doctype html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script>
</head>

<body ng-app="">
  <button ng-mouseenter="lastEventType=$event.type">
    Enter
  </button>
  Event type: {{lastEventType}}
</body>

</html>