Andi Giga
Andi Giga

Reputation: 4162

ng-mouseleave triggers on mouseenter

I attached the ng-mouseleave event to my html tag. Unfortunately it triggers twice. Once when the user leaves the website which is fine and once when he enters the website, which is not wanted. I have a console.log on the event.

The plunkr: http://run.plnkr.co/plunks/rjfyCw/

index.html

    <html ng-app="myApp" id="myApp" ng-controller="MainController as mainCtrl" ng-mouseleave="mainCtrl.log('xy')">

Controller.js

myAppControllers.controller('MainController', [ function () {
    this.log = function(log) {
      console.log(log);
    };

  }]);

Upvotes: 1

Views: 1032

Answers (1)

Rasalom
Rasalom

Reputation: 3111

That's because event is triggered on child elements as well, you need to stop this manually:

ng-mouseleave="mainCtrl.log($event, 'xy')"

and

this.log = function($event, log) {
      $event.stopPropagation()
      console.log(log);
    };

http://plnkr.co/edit/sSpqiIqMz3rVYzrPQ0iC?p=preview

Upvotes: 1

Related Questions