Reinitialize the controller on state change


#1

I have an app that progresses the user through several views and at the last view a button to send the user back to the beginning to start over. The start over button uses $location.Path(’/’) to take the user back to the beginning but the controllers are not reinitialized and so the model is not refreshed


#2

In (I think it was) beta 14 the introduced view caching. So basically every state gets cached and brought back. I was worried about it when I first got started converting my app, but I’ve actually found it nice. It gives you a chance to clean things up manually if you need.

The “Caching” section (about half way down) http://ionicframework.com/docs/api/directive/ionNavView/

has some great resources. It shows you how to define states that down cache, or disable it entirely. Just remember that caching can improve the user experience by making the app work faster because you don’t have to re-initialize the entire controller on every state change. So my recommendation is if you can avoid turning the caching off on a state, then do so. Your case should be fine however.


#3

You can use

$window.location.reload(true);


#4

Awesome that’s just what I needed thanks


#5

Thanks it solve my problem.