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?