3

I am writing a small shopping application using angularJS. I would like to be able to prevent the templates of certain $states from caching, e.g. the order review state. My problem is that a user may change an order and then use the browser-next-button to go to the order review page. The page loads a template with some server-prepared shopping cart data.

I'd be fine with the templates of other states (like a product description state) to be cachable. Therefore I would not want to use $templateCache.removeAll();.

On https://gist.github.com/claudemamo/9092047#file-app-2-js I've found this:

app.run(function($rootScope, $templateCache) {
    $rootScope.$on('$routeChangeStart', function(event, next, current) {
        if (typeof(current) !== 'undefined'){
            $templateCache.remove(current.templateUrl);
        }
    });
});

where I would probably just do something similar every time the state changes for all the states I don't want to be cached.

Should I just check which template I am loading and then remove it from the cache if I don't want it to be cached?

Amelse Etomer
  • 1,153
  • 8
  • 22
  • Would this Q/A help you: http://stackoverflow.com/questions/23589843/disable-template-caching-in-angularjs-with-ui-router – Daniel Nalbach Jan 21 '16 at 15:27
  • The question is not clear. You ask about caching states but the example code is about template caches. – Steve Campbell Jan 28 '16 at 02:24
  • @SteveCampbell I've clarified the question, as it was unclear. As now stated above, I want to prevent the templates of specific states from being cached. – Amelse Etomer Feb 10 '16 at 18:08

0 Answers0