<!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对指令模板进行转换
最新推荐文章于 2023-03-27 15:09:48 发布