This article introduces the method of AngularJs to prohibit template caching, share it with everyone, and also leave a note for yourself, which has the following:
Because of the characteristics of AngularJs (or the browser itself cache?), the default HTML template loading of angular will be cached. This leads to the fact that after modifying the template, you often need to clear the browser's cache to ensure that the browser obtains the latest html template. It's okay to test it yourself, but if the server's template content is updated, the user will not cooperate with you to clear the browser's cache. Therefore, this is really a big problem.
(function($routeProvider, $locationProvider) { $routeProvider .when('/Book/:bookId/ch/', { templateUrl: '', controller: 'ChapterController' }); });
Method 1: Add a timestamp (or other random numbers) after the template file path, and force AngularJs to load a new template from the server each time.
(function($routeProvider, $locationProvider) { $routeProvider .when('/Book/:bookId/ch/', { templateUrl: '' + '?datestamp=' + (new Date()).getTime(), controller: 'ChapterController' }); });
But this method is too unsightly. . . .
Method 2: Use $templateCache to clear the cache
// Forbidden template caching(function($rootScope, $templateCache) { $rootScope.$on('$routeChangeStart', function(event, next, current) { if (typeof(current) !== 'undefined'){ $(); } }); });
After configuring the routing address, adding this code later, AngularJs can be forbidden from cache templateUrl.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.