Hof*_*ffZ 2 javascript templates caching angularjs
当我的Angular控制器初始化时,我需要缓存一些HTML文件.
根据Angular $ templateCache文档,我可以将HTML模板添加到Angular中:
$templateCache.get('templateId.html')
Run Code Online (Sandbox Code Playgroud)
但我不能让这个工作.我试图在控制器内和模块run()函数(Plunker)中获取模板文件.但我可以在网络控制台中看到未提取模板.
app.run(function($templateCache) {
$templateCache.get('templ.html');
});
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
您必须使用http请求获取html,然后您可以将其存储在模板缓存中.例如:
$http.get('templ.html', {
cache: $templateCache
}).then(function(result) {
console.log(result);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11946 次 |
| 最近记录: |