Javascript 角度:从缓存中删除特定模板
我知道如何通过删除缓存中的所有模板Javascript 角度:从缓存中删除特定模板,javascript,angularjs,angular-ui-bootstrap,Javascript,Angularjs,Angular Ui Bootstrap,我知道如何通过删除缓存中的所有模板 $templateCache.removeAll(); 但我只想从缓存中删除特定模板。 模板不是从$routeProvider加载的,而是通过使用从指令中呈现的 templateUrl: 'template/page/file.html' 我的应用程序结构如下 -web - js - controllers - appController.js - templates - page - file.html
$templateCache.removeAll();
但我只想从缓存中删除特定模板。
模板不是从$routeProvider
加载的,而是通过使用从指令中呈现的
templateUrl: 'template/page/file.html'
我的应用程序结构如下
-web
- js
- controllers
- appController.js
- templates
- page
- file.html
我做了
$templateCache.remove('/templates/page/file.html')在appController.js中的code>尝试在应用程序的run方法中执行此操作:
app.run([
"$rootScope", "$templateCache", "authService", function($rootScope, $templateCache, authService) {
$rootScope.$on("$routeChangeStart", function(event, next, current) {
if (typeof (current) !== "undefined") {
$templateCache.remove(current.templateUrl);
}
});
}
]);
基于,因为后者有一个.remove(键),所以它也可以在$templateCache上工作。也许你拿错钥匙了
你可以试着打电话给.get(key)
检查你是否有正确的钥匙(我怀疑你没有-这就是原因。remove(key)
不适合你)
可能模板文件的路径弄乱了密钥,相对路径可能不是实际的密钥,而是完整路径或文件名。问题在于我的代码,函数触发器不正确。我用计算机解决了它
$rootScope.$on('$viewContentLoaded', function() {
$templateCache.remove('templates/page/file.html');
});
因此,现在在加载页面时,模板将从缓存中删除。
谢谢您的帮助。您是否尝试过像$templateCache.remove('template/file.html')。。。。我认为这是一个常见的缓存系统,它使用then路径和视图名称作为键是的,我尝试过,但它对我不起作用remove(key)
应该起作用。@tasseKATT在key
中写什么。你能举个例子吗?第一个答案告诉我们$templateCache实际上使用$cacheFactory链接:试试这个:$cacheFactory.Cache.remove('yourTemplate')信息:没有发生$routeChange。我在问题中提到了这一点。它是从指令加载的。我已经编辑了这个问题。你能告诉我钥匙放在哪条路上吗?