为什么templateCache不能在angular js中工作
why templateCache not working in angular js?
我正在尝试使用$templateCache。但当我使用$templateCache.get()进行控制台操作时,它会给我未定义的结果。。为什么?
http://plnkr.co/edit/MAXQmzTVR8fpsw645rct?p=preview
<script>
angular.module('app',[ ]).directive('h',function($templateCache){
console.log($templateCache.get('about.html'))
var element=angular.element('<input type="text" ng-model="message"><div>{{message}}</div>');
return { restrict:'E',
scope:{},
templateUrl:'a.html',replace:true,
transclude:true,
compile:function(tElement){
tElement.append(element);
return function(s,e,a){
s.$watch('message',function(val){
// console.log('------'+val)
})
}
}
}
})
</script>
**console.log($templateCache.get('about.html'))** give me undefined why ?
因为当前您正在注册该指令的同时运行该语句。那一次$templateCache
中没有模板。您需要将该行放入指令compile
函数中,然后只有您才能在其中获得数据。
看到这个问题,我认为这应该会帮助你
Angular Tabs渲染具有缓存的模板;ng包含src";
模板被加载到模板缓存中,以便快速检索。您可以通过$templateCache服务直接加载模板。
angular.module('app', []).run(function($templateCache) {
$templateCache.put('a.html');
});
要检索,只需在HTML 中使用它
<div ng-include=" 'a.html' "></div>
或
$templateCache.get('a.html')
相关文章:
- 如何使用多个jquery版本,以便Responsive Slides.js工作
- 无法使FlowType.js工作
- Intellisense没有;t在VS2013中为JS工作
- 有人能解释一下如何#ifeq吗/section键使用handle.js工作
- 使dropzone.js工作的傻瓜指南
- 如何获得侧边栏.js工作
- 如何在没有 Web 服务器的情况下做出响应.js工作
- 创建JS工作,但不显示工具栏
- 无法获得简单的敏捷.js工作
- 通过有错误的 Ajax-Request 打印出 HTML 会阻止进一步的 JS 工作
- Angular JS-工作函数中的“错误:[$interpole:interr]Can't interpole:
- 推特's Bootstrap Popover:赢得't工作,即使其他JS工作正常
- 可以'不要让typeahead.js工作
- 无法让Quicksand.js工作
- 通过Grunt使用Node.js工作SASS预处理器
- 可以'不要让popcorn.js工作
- 不能让Bootstrap modal.js工作
- 我怎么能与wordpress中的wow.min.js工作
- 无法让haxe-pixi.js工作-我得到一个空白的白色屏幕
- 不能让impress.js工作