我有一个通过指令使用模板的Angular。我拥有的其中一个模板有一个bug。在进行更改并刷新我的浏览器后,我注意到它没有使用我修复了错误的文件。然后我学习了模板缓存。很棒的功能,但是我如何为这个更新的模板清除缓存呢?
注意:我没有使用Angular的路由。只是通过一个指令访问模板。
发布于 2015-06-26 14:17:41
你用的是Grunt还是Grunt?
我个人使用template-cache,它的作用是收集所有html部分/模板,并将它们放到js文件中。
优点:*所有模板一次加载到一个js文件中。
缺点:*每次更改html文件时,都必须重新生成模板缓存。您可以使用gulp来查看您的html文件,每次您更改某些内容时,它都会自动为您重新生成模板缓存:)
总而言之,使用gulp-watch和gulp-angular-templatecache来解决您的问题。
发布于 2015-07-28 08:42:13
作为对模板urls附加数字的扩展,您可以考虑截取请求(所有请求)并在其中附加数字(版本、版本、日期等)。如下所示:
angular.module('my-app', []).config(function($httpProvider) {
$httpProvider.interceptors.push(function($window) {
return {
'request': function(config) {
// just yours (other libs, ie pagination might conflict with
// their own insertions)
if (!/^\/path-to-your-templates\//.test(config.url)) {
return config;
}
// pull a # from wherever you like, maybe the window - set by
// your backend layout engine?
if ($window.version) {
if (!config.params) {
config.params = {};
}
if (!config.params.v) {
config.params.v = $window.version;
}
}
return config;
}
};
});
});https://stackoverflow.com/questions/31065414
复制相似问题