Safely Prevent Template Caching in AngularJS [team]

posted in: AngularJS | 0

AngularJS’s $templateCache can be a pain in the ass. Sometimes we don’t want templates to be cached. With the UI Bootsrap module, a┬ásolution is to remove new cache entries on route change instead of indiscriminately removing all entries:

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

http://opensourcesoftwareandme.blogspot.com/2014/02/safely-prevent-template-caching-in-angularjs.html

Leave a Reply