Hello guys,
So I tried to use clearCache() in my app to clear all cached views whenever reaching a specific state. I tried with a function when the button leading to that state is clicked :
$scope.switchEvent = function() {
$ionicHistory.clearCache();
$state.go("welcome");
}
That call was from a nested state (called “app.main”). Didn’t work. When clicking on the link that gets me back to “app.main” with a different parameter for the page (should be different data), the cached view shows up, with the old data. Note that if using the inline
cache-view="false"
Directly on the view, it works.
So I tried something else. On the “.run” function, I added :
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams){
if(toState.name == "welcome")
$ionicHistory.clearCache();
});
Using this didn’t work either. The clearCache() was triggered (I checked it with a console.log) but didn’t clear any cached view. But if I used no condition and launch clearCache() on every view change, it worked. I ended up with this
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams){
if(fromState.name.substr(0, 4) != "app." && (toState.name == "app.main" || toState.name == "app.mainSecondary"))
$ionicHistory.clearCache();
});
So this works, but I’m not satisfied as it’s not very robust… Apparently only clearCache() when changing to the wanted view works. Not sure if it’s linked to the nested states or what, but there you go…
@adam I wanted to reference this issue in Please help test: Angular 1.3, improved transitions, cached views, etc but it’s closed