效果是鼠标移动到此div下就自己加载自己div下的load事件
<div ng-controller="f1"> <div load date="rundate()">加载数据...</load> </div> <div ng-controller="f2"> <div load date="rundate2()">加载数据...</load> </div>
<script>
var myapp=angular.module('myapp',[]);
myapp.controller('f1',function($scope){
$scope.rundate=function(){
console.log('数据1');
}
});
myapp.controller('f2',function($scope){
$scope.rundate2=function(){
console.log('数据2');
}
});
myapp.directive('load',function(){
return{
restrict:'A',
link:function(scope,element,attrs){
element.bind('mouseenter',function(){
scope.$apply(attrs.date);
})
}
}
});
</script>