1

I am using AngularJS and have implemented routing using it. I want to make sure whenever route changes template is fetched from server and not obtained from cache, is there a way I can force this to happen ?

1

2 Answers 2

5

This should hopefully work:

app.run(function($rootScope, $templateCache) {
   $rootScope.$on('$viewContentLoaded', function() {
      $templateCache.removeAll();
   });
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks your fix is working but I get following error as mu page loads: TypeError: Cannot read property 'removeAll' of undefined at localhost:8080/ui/app/js/angular/app.js:294:21
putting a null check for $templateCache helped...thanks
0

According to the comment on the accepted answer, this should be the correct code:

app.run(function($rootScope, $templateCache) {
   $rootScope.$on('$viewContentLoaded', function() {
      if($templateCache) {
         $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.