<!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>
示例: