templateCache
templateCache如何让多个指令去使用?
templateCache如何让多个指令去使用?
2016-09-30
$templateCache是module里面的全局对象,同一个模块里的指令都可以共享一个$templateCache
var myModule = angular.module("MyModule", []);
//注射器加载完所有模块时,此方法执行一次
myModule.run(function($templateCache){
$templateCache.put("hello.html","<div>Hello everyone!!!!!!</div>");
});
myModule.directive("hello", function($templateCache) {
return {
restrict: 'AECM',
template: $templateCache.get("hello.html"),
replace: true
}
});
myModule.directive("hi", function($templateCache) {
return {
restrict: 'AECM',
template: $templateCache.get("hello.html"),
replace: true
}
});举报