0

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);
                }
            );
  }]);
2
  • Isn't there a cache property that you can pass in as config. Commented Aug 20, 2014 at 15:00
  • Something like this? .factory('Clients', ['$resource', function ($resource) { return $resource(pathApi, {}, { query: { method: 'GET', isArray: false, cache: false } }); }]) Commented Aug 20, 2014 at 15:14

2 Answers 2

1

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() }
        }
    });
}])
Sign up to request clarification or add additional context in comments.

Comments

0

This seems to work for me:

app.run(function($rootScope,$templateCache) {
  $rootScope.$on('$viewContentLoaded', function() {
    $templateCache.removeAll();
  });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.