<!doctype html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="http://apps.bdimg.com/libs/angular.js/1.3.9/angular.min.js"></script>
</head>
<body>
<div alotofhello=5>
<p>hello angularJs</p>
</div>
<script>
var myApp=angular.module('myApp',[]);
myApp.directive('alotofhello',function(){
return {
restrict:'AE',
compile:function(element,attrs,transclude){
console.log("指令編譯。。。。");
var tpl=element.children().clone();
console.log(tpl);
for(var i=0;i<attrs.alotofhello-1;i++){
element.append(tpl.clone());
}
return function(scope,element,attrs,controller){
console.log("compile函數返回的link函數");
}
}
}
});
</script>
</body>
</html>
compile對指令模板進行轉換
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.