It seems to be some SIMPLE PROBLEM but I am looking on it for some hours and cannot find the answer. Why mouseout or mouseleave doesnt work where mouseover works? Here is the code:
HTML:
<div ng-app="test">
<div class="testdiv" data-test-mouseout=""></div>
</div>
CSS (not important in this case I suppose):
.testdiv {
width: 100px;
height: 50px;
margin: 25px;
background: yellow;
position: relative;
}
.testHere {
position: absolute;
padding: 0;
margin: 0;
background: red;
width: 100%;
height: 10px;
top: -5px;
left: 0px;
}
JS:
var app = angular.module('test', []);
app.directive('testMouseout', function ($compile) {
return {
link: function (scope, iElement) {
iElement.bind('mouseover', function () {
iElement.html('<div data-test-mouseout-here="" class="testHere"> </div>');
$compile(iElement.contents())(scope);
});
}
};
});
app.directive('testMouseoutHere', function () {
return {
link: function (scope, iElement) {
iElement.bind('mouseout', function (e) {
e.target.style.backgroundColor = 'blue';
console.log('mouseout');
});
}
};
});
Ok, what it supposed to do? It will display yellow div 100x50px and when you mouseover it, then new red div appear inside as an child. This red div has mouseout binding so it should console.log "mouseout", but it doesnt happened. BUT if you raplace mouseout by mouseover in second directive, it works. Thats weird.
I was trying to put ngMouseout/ngMouseleave into template inside first directive, but same problem. ngMouseout/ngMouseleave didnt work ngMouseover worked.
Here is fiddle:http://jsfiddle.net/rGAqw/
Same in plunker:http://plnkr.co/edit/JPiHYO79QaNrJerMM59a