我正在使用AngularJS并使用它实现了路由。我想确保每当路由更改模板从服务器获取而不是从缓存中获取时,有没有办法可以强制这种情况发生?
答案 0 :(得分:6)
这应该有用:
app.run(function($rootScope, $templateCache) {
$rootScope.$on('$viewContentLoaded', function() {
$templateCache.removeAll();
});
});
答案 1 :(得分:0)
根据对已接受答案的评论,这应该是正确的代码:
app.run(function($rootScope, $templateCache) {
$rootScope.$on('$viewContentLoaded', function() {
if($templateCache) {
$templateCache.removeAll();
}
});
});