在 AngularJS 中手动清除 $templateCache 的最佳方法 [英] Best way to manually clear out $templateCache in AngularJS
问题描述
我正在开发一个系统,该系统有很多 html 模板文件在整个系统中使用.
I'm working on a system that has a lot of html template files being used all throughout the system.
问题是当我部署更新时,用户无法看到 html 更改,因为他们的浏览器正在使用它们的缓存版本.到目前为止,我能够让用户看到 html 更新的唯一方法是让他们执行浏览器的硬重新加载.
The problem is when I deploy updates, users are unable to see html changes because their browsers are using the cached version of them. So far, the only way I am able to get users to see html updates is to have them perform a hard reload of their browser.
出于显而易见的原因,这并不理想.随着 mre 用户迁移到此系统,确保每个人都执行该操作已成为一项繁琐的工作
For obvious reasons this is not ideal. As mre users migrate to this system, it has become a tedious chore making sure everyone performs that action
有没有办法强制访问系统的浏览器按照我的命令清除模板缓存?也许在登录系统时手动清除它?
Is there a way I can force browsers accessing the system to clear template cache at my command? Maybe manually clear it upon logging into the system?
推荐答案
$templateCache.removeAll()
很好的去除模板缓存
示例代码
myApp.run(function($rootScope, $templateCache) {
$rootScope.$on('$viewContentLoaded', function() {
$templateCache.removeAll();
});
});
这篇关于在 AngularJS 中手动清除 $templateCache 的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!