angularjs之directive

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body ng-app="myApp">

<div ng-controller="myController">
    <hello>qq</hello>
</div>
<script>
    var app = angular.module("myApp",[]);
    app.controller("myController",["$scope",function($scope){
        $scope.loadData=function(){
            console.log("载入数据");
        }
    }]);
    app.directive("hello",function(){
       return {
           restrict:"AE",
           link:function(scope,element,attr){
               element.bind("mouseenter",function(){
                   scope.loadData();
               })
           }
       }
    })
</script>

</body>
</html>

指令2
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script> 
</head>
<body ng-app="myApp">

<run></run>

<script>
var app = angular.module("myApp", []);
app.directive("run", function() {
    return {
        template : "<h1>自定义指令!</h1>"
    };
});
</script>

</body>
</html>


nickname
content