我试图禁用我的AngularJS应用的缓存,但它不与下面的代码工作:
$http.get("myurl",{cache:false})
当我使用"myurl&random="+Math.random()
,缓存为禁用;但是,我想要一个不同的方法。
我试图禁用我的AngularJS应用的缓存,但它不与下面的代码工作:
$http.get("myurl",{cache:false})
当我使用"myurl&random="+Math.random()
,缓存为禁用;但是,我想要一个不同的方法。
这已经回答here。
从链接粘贴代码片段供您参考。
myModule.config(['$httpProvider', function($httpProvider) {
//initialize get if not there
if (!$httpProvider.defaults.headers.get) {
$httpProvider.defaults.headers.get = {};
}
// Answer edited to include suggestions from comments
// because previous version of code introduced browser-related errors
//disable IE ajax request caching
$httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
// extra
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
}]);
Coool!解决了我的问题..谢谢你们! – Saxophonist
我建议不要使用Pragma。这不是一个标准(显然),并可能会导致Cross Origin请求出现问题。刚刚完成了与朋友的2小时调试会话,了解这是问题的原因。 –
尝试这样
$state(' 'app.name', {
url: '/name',
cache: false,
controller:'MainCtrl',
templateUrl:'templates/name.html'
})
不知道这个答案是如何应用的。问题是关于http get。不是模板。 – tatmanblue
myApp.config(function ($routeProvider) {
$routeProvider.
when('/', {controller: 'MyCtrl', templateUrl: '/eshop/myConfig'})
})
.controller('MyCtrl', function ($scope, $templateCache) {
$templateCache.remove('/eshop/myConfig');
// or
$templateCache.removeAll();
});
我没有测试它。我发现了一些在这个url.Have看看这个 Angularjs - how to clear $routeProvider's caches of templateUrl
这里是我做的,只是将其更改为
$http.get("myurl",{headers:{'Cache-Control': 'no-cache'}})
这已经回答了[这里](http://stackoverflow.com/questions/16098430/angular-ie-caching-issue-for-http)。 – user6408463
可能重复[Angular IE缓存问题$ http](https://stackoverflow.com/questions/16098430/angular-ie-caching-issue-for-http) –