在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()
是很好的去除模板缓存
$templateCache.removeAll()
is good to remove template cache
例如code
myApp.run(function($rootScope, $templateCache) {
$rootScope.$on('$viewContentLoaded', function() {
$templateCache.removeAll();
});
});
这篇关于在AngularJS手动清除$ templateCache最好的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!