Clear cache when change between tabs


I’m working with Ionic 2, and I want to clear cache when I change a tab. Now, if I do something in one tab and change something, when I change the tab and then comeback, the tab will be in the same place.


This should do the trick.

ngAfterViewInit() {

Just paste this code in your pages .ts file ‘ngAfterViewInit’ basicly means this code will be executed when you leave the page.

thanks,but $ionicHistory work in ionic1,ionic2 do not have $ionicHistory

Then you could use navPop, it should remove the page from the cache then.


changing between tabs


I don’t know what you mean, but you can add this to your pages if you want to clear their cache after you viewed them.

ngAfterViewInit() {

Hey @cherry, what @liuya891012 means is that all the Tabs are placed in just one Navigation page for the NavController… so there’s no way to do what you’re saying. Anyone came up with a correct answer for this problem?

Can’t say it’s a correct answer, but my answer is that this is not a problem. It is the way users expect tabs to behave, and I consider it flawed design to make them do otherwise.

Let’s say the currently selected tab is tab A. I expect clicking on tab B and then tab A again to put me in the exact same position I am right now. Don’t break that UX contract.

1 Like