指令的本质其实是一个替换的过程。
compile阶段进行标签的解析和变换,link阶段进行数据绑定等操作
指令缓存
var app = angular.module('app',[]);
//注射器加载完所有模板时,此方法执行一次,缓存一下。以便在多个地方使用
app.run(function($templateCache){
$templateCache.put("hello.html","<div>Hello everyone!!</div>")
}).directive("hello",function($templateCache){
return {
restrict : "ACEM",
templateUrl : "hello.html",
replace : true
}
})
网友评论