我想要使用$ templateCache.But当我使用$ templateCache.get()时,它给我一个未定义的..why?为什么templateCache不能在角js中工作?
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.get('about.html')'之前''templateCache.put('about.html','
')'',在你的例子中,其中的about.html是? –