angular.module('myApp',[])
.directive('hello',function(){
return {
restrict : "AE",
transclude : true,
template:"<div>Hello everyone!<div ng-transclude></div></div>"
}
})
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="UTF-8">
<title></title>
<script src="../js/angular.min.js"></script>
<script src="js/$transclude.js"></script>
</head>
<body>
<hello>
<div>這裏是指令內部的內容。</div>
</hello>
</body>
</html>
結果:
Hello everyone!
這裏是指令內部的內容。
可以看出hello指令的內部內蓉<div>這裏是指令內部的內容。</div>被插到到了
<div ng-transclude></div>之間了
<hello>
<div>這裏是指令內部的內容。</div>
</hello>
這樣就能實現指令內部使用指令了。