Reload controllers on state change not working in version 14

Hey guys. I started working on my Ionic project 6 months ago, with Ionic version 13. After upgrading to version 14, I noticed that the controllers did not reload when navigating between different states in the app any more. Some of my code relies on that the controllers are reloaded when switching states.

I have tried setting the reload parameter in UI router to true, without any luck:

$state.go(‘login’, {}, {reload: true})
$state.transitionTo(‘login’, {}, {reload: true});

I isolated the issue by starting a new, blank Ionic project, version 14. The controllers are not reloading, even with the {reload: true} parameter set as shown above. However, after replacing the Ionic lib files with version 13, the behavior is as expected, and the controllers are reloaded on state change.

I really appreciate help with how I can reload a controller when navigating through states in version 14. Or pointing me in a direction of where I may have misunderstood something. Thanks!

Its by design, the views are cached.

Try this:

$stateProvider.state('myState', {
   cache: false,
   url : '/myUrl',
   templateUrl : 'my-template.html'
})

Read about caching here http://ionicframework.com/docs/api/directive/ionNavView/

Hope it helps!

12 Likes

Beautiful BioPhoton, you saved my day!
Thank you very much!

I am facing the same issue…But for my case I have long list of 700 items and selecting them and moving to a new state and returning back.also for the same state,I have to refresh the page with new set of data.If I am doing cache:false,I am able to refresh the data but then I have to maintain the scroll and selection array as well I’ll loss the data from cache what I am fetching on infinite scroll…Any help is appreciated…

Could you post a bit of your code?

Perfect, this is exactly the solution I needed!

Thanks!

sorry its cannot work for my case

Is there any way only set cache to false in certain condition? For example, return from certain state?

1 Like

Hey there, just to add my 2¢, setting cache to false can be bad for performance. Since the view has to be rebuilt every time, you loose out on having the view instantly ready. Also, you loose on about having things like swipe to go back.

It’s much better to use the viewLife Cycle events instead

3 Likes

Agreed… using $scope.$on('$ionicView.beforeEnter') works super well for reloading data in a cached view!

none of the solutions worked for me. I’m uploading an avatar from the camera plugin and updating the image model dynamically. However, looks like the image is not being rerendered. Same happens for text.

I had a problem which could be similar to this. Turns out the web view caches image paths so if you update an image file but the path/filename is the same, the image does not update in the app until the whole app is restarted.

Thanks a ton for the quick solution