Angular学习(8)- directive

<!DOCTYPE html>
<html ng-app="MyApp">
<head>
    <title>Study 9</title>
    <script type="text/javascript" src="js/angular.js"></script>
</head>
<body>
    <div ng-controller="testController">
        <hello say="content">Grid</hello>
    </div>
    
    <script type="text/javascript">
        var app = angular.module("MyApp", [], function() { });
        app.controller("testController", function($scope) {
            $scope.content = "I love you.";
        });
        app.directive("hello", function() {
            return {
                restrict: "E",
                template: "<div>hello,<b ng-transclude></b>,{{cont}}</div>",
                replace: true,
                transclude: true,
                scope: {
                    cont: "=say"
                }
            };
        });
    </script>
</body>
</html>

 

示例:

 

posted @ 2014-03-28 15:18  横渡  阅读(977)  评论(0编辑  收藏  举报