Disable controller when hitting back button

So, for my main page, my use case is I have to set the cache-view=“false”, so no matter what the fromState is, it will fire the controller. Now, the problem is, when I hit the back button on detail page and come back to main page, it is also calling the controller. Can I programmatically disable the controller for back button ?


When you set cache-view=false you are telling ionic to delete the instance of the controller and the template after you navigate away.

So when you navigate back there isn’t an instance of the controller and ionic/angular has to create it.

So no, there isn’t a way to programatically not instantiate(call) a controller when you press back and you’ve set cache-view=false.

What you can do is set cache-view=‘true’ and then just listen to the events (see section ‘View LifeCycle and Events’ in http://ionicframework.com/docs/api/directive/ionView/) and then move whatever logic gets called when the controller is instantiated into the callback for one of those events and then perhaps have some checks so that stuff is only called under certain circumstances…

Thanks for the answer, I was thinking similar thing using ‘$stateChangeStart’, but using ‘$ionicView.beforeEnter’ is way simpler