compile对指令模板进行转换

来源:互联网 发布:js 跨域 编辑:程序博客网 时间:2024/06/10 13:49
<!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>
0 0
原创粉丝点击