Disabling AngularJS $ HTTP Cache

I am trying to disable the cache in my AngularJS application, but it does not work with the following code:

$http.get("myurl",{cache:false}) 

When I use "myurl&random="+Math.random() , the cache is disabled; but I need a different approach.

+8
angularjs caching
source share
4 answers

It has already been answered here .

Insert code snippet from link to link.

 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'; }]); 
+18
source

try it

  $state(' 'app.name', { url: '/name', cache: false, controller:'MainCtrl', templateUrl:'templates/name.html' }) 
+1
source

Here is what I did, just change it to

  $http.get("myurl",{headers:{'Cache-Control': 'no-cache'}}) 
+1
source
 myApp.config(function ($routeProvider) { $routeProvider. when('/', {controller: 'MyCtrl', templateUrl: '/eshop/myConfig'}) }) .controller('MyCtrl', function ($scope, $templateCache) { $templateCache.remove('/eshop/myConfig'); // or $templateCache.removeAll(); }); 

I have not tested it. I found something in this url. Look at this Angularjs - how to clear $ routeProvider caches from templateUrl

0
source

All Articles