I had this problem in a project that i worked on. I tried these methods.
Method 1 : Setting cache property false of different states.
var core = angular.module('app.core');
core.cofigure(configure);
configure.$inject = ['$stateProvider'];
// Configuration Function
function configure($stateProvider){
$stateProvider
.state('login', {
url: '/login/:redirect/:viewId',
cache: false, // Here i have set the cache property to false
templateUrl: 'app/layout/login.html'
})
.state('home', {
url: "/home",
cache: false, // Here also
abstract: true,
templateUrl: 'app/layout/container.html'
});
}
Now this method was fine, But it was not working at random times and in the Internet Explorer.
Method 2 : Adding a Timestamp to the template URL.
// I created a timestamp string with the current time.
var date = new Date().getTime().toString();
$stateProvider
.state('login', {
url: '/login/:redirect/:viewId',
cache: false,
// Now i append it here
templateUrl: 'app/layout/login.html' +'?' + date
})
.state('home', {
url: "/home",
cache: false,
abstract: true,
templateUrl: 'app/layout/container.html' + '?' + date // Here also.
});
This method is what we decided on after searching for possible fixes to this problem. However no caching takes place in this case. Each GET Request for the template file is different and it will guarantee that the template loaded will be the updated one. But if you are building a web application that has a lot of templates and client side performance is essential, this method won't be helpful.
Method 3 : require templates
I recommend this method. You can use require.js in your application to load the templates when javascript executes. This will load the templates when the running the application for development purpose and also when you minify your code for production. Since the templates are loaded into the javascript code, you don't have to keep the html template files when deploying to production as well.
$stateProvider
.state('login', {
url: '/login/:redirect/:viewId',
// Note 'template' and not 'templateUrl'
template: require('app/layout/login.html')
})
.state('home', {
url: "/home",
abstract: true,
template: require('app/layout/container.html')
});