【发布时间】:2014-10-23 05:18:37
【问题描述】:
我遇到了 IE 缓存所有内容的问题,所以如果我切换用户,我仍然会看到来自不再登录的旧用户的数据。
我尝试了这个解决方案(在:Angular IE Caching issue for $http 找到),它工作了,但现在我的指令无法获取它需要的模板,我怎样才能让这两个东西都工作?
代码:
app.config(['$httpProvider', function ($httpProvider) {
//initialize get if not there
if (!$httpProvider.defaults.headers.get) {
$httpProvider.defaults.headers.get = {};
}
console.log($httpProvider.defaults.headers.get['If-Modified-Since']);
//disable IE ajax request caching
$httpProvider.defaults.headers.get['If-Modified-Since'] = '0';
}]);
我的指令:
app.directive('commentsContainer', function (commentResource, signalRService) {
return {
restrict: 'EAC',
templateUrl: '/Templates/Directives/_Comments.html',
link: function ($scope) {
//CODE
}
}
编辑! 无论哪种浏览器都会出错,这是来自 chrome 的错误:
GET http://localhost:58991/Templates/Directives/_Comments.html 400 (Bad Request)
Error: [$compile:tpload] Failed to load template: /Templates/Directives/_Comments.html
没有用于缓存的角度片段,它可以正常工作..
希望你能帮忙!
【问题讨论】:
-
你是什么意思“不能”,你得到一个错误?它提出请求吗?请注意,IE 没有
console,除非您确实打开了控制台,否则可能会导致它中断。 -
哦,对不起。生病添加错误。我的坏
-
尝试添加这些标题:
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache'; $httpProvider.defaults.headers.get['Pragma'] = 'no-cache'; -
嗯,它似乎工作。但我不得不删除 $httpProvider.defaults.headers.get['If-Modified-Since'] = '0';
标签: javascript angularjs internet-explorer caching