UPTATE! 以前的解决方案是一种解决方法。您现在可以使用角度指令(https://docs.angularjs.org/api/ng/directive/ngMouseenter)。
ng-mouseenter="handler()"
以前的解决方案(解决方法)
HTML:
<div simulate-mouse eventhandle="objfromscope">Hover</div> <!-- objfromscope: true or false -->
<div ng-click="objfromscope=!objfromscope">Enable/Disable hover</div>
指令
app.directive('simulateMouse', function() {
return {
restrict: 'AE',
scope: {
eventhandle : '=eventhandle' //eventhandle is two way data binded
},
link: function(scope, element, attrs) {
scope.$watch(function() {
return scope.eventhandle;
}, function(newValue) {
console.log(newValue)
if(newValue){
element.off("mouseenter").on("mouseenter",function(){
onMouseOverCall()
});
}else{
element.off("mouseenter");
}
});
var onMouseOverCall = function(){ /* called only when eventhandle is true */
console.log("hoho")
}
}
};
});
不会是简单的使用范围变量,如'NG东西“类”? – charlietfl 2014-12-05 15:29:00
还有其他的行为,我不能改变的元素,这就是为什么我要绕模拟鼠标的路线。 – 2014-12-05 15:30:19
你将不得不创建一个事件对象,然后包括坐标并触发mouseover – charlietfl 2014-12-05 15:31:54