Reputation: 21
I need you to clear the cache always. But when I create, update or delete a client, always get the same result. Only when I delete the cache manually (Ctrl+Shift+Supr) I can see the new data.
.factory('Clients', ['$resource', function ($resource) {
return $resource(pathApi, {}, {
query: {
method: 'GET',
isArray: false
}
});
}])
angular.module('app.controllers').controller('controller', ['$scope','Clients', function ($scope, Clients) {
Clients.get().$promise.then(
//success
function (value) {
$rootScope.clients= value;
},
//error.
function (error) {
alert(error);
}
);
}]);
Upvotes: 0
Views: 1819
Reputation: 21
Here is the solution. Add a time variable to the request: params: { 'foobar': new Date().getTime() }
.factory('Clients', ['$resource', function ($resource) {
return $resource(pathApi, {}, {
query: {
method: 'GET',
isArray: false,
params: { 'foobar': new Date().getTime() }
}
});
}])
Upvotes: 1
Reputation: 1860
This seems to work for me:
app.run(function($rootScope,$templateCache) {
$rootScope.$on('$viewContentLoaded', function() {
$templateCache.removeAll();
});
});
Upvotes: 1