Because of the Angularjs feature (or the cache of the browser itself.) , angular the default HTML template load is cached. The result is that every time you finish modifying the template, you often need to clear the browser's cache to ensure that the browser to get the latest HTML template, the test is OK, but if the server's template content is updated, users will not be each with you to clear the browser's cache. So it's really a big problem.
App.config (function ($routeProvider, $locationProvider) {
$routeProvider
. When ('/book/:bookid/ch/', {
Templateurl: ' chapter.html ',
controller: ' Chaptercontroller '
});
Method One: Add a timestamp (or other random number) after the template file path to force Angularjs to load the new template every time from the server
<pre name= "Code" class= "JavaScript" >app.config (function ($routeProvider, $locationProvider) {
$ Routeprovider
. When ('/book/:bookid/ch/', {
templateurl: ' chapter.html ' + '? datestamp= ' + (new Date ()). GetTime (),
controller: ' Chaptercontroller '
});
But this method is not very beautiful ....
Method Two: Use $templatecache to clear the cache
Prevents the template cache
App.run (function ($rootScope, $templateCache) {
$rootScope. $on (' $routeChangeStart ', function ( Event, Next, current] {
if (typeof (current)!== ' undefined ') {
$templateCache. Remove (Current.templateurl);
}
});
});
After configuring the routing address, adding this code after app.config, you can prevent Angularjs from caching templateurl.