I'm developing a view that need call multiples methods of a webservice every time the view is opened, should i use $scope.$on('$ionicView.enter', function(){...})
or cache:false
?
What is the real difference between each one?
I'm developing a view that need call multiples methods of a webservice every time the view is opened, should i use $scope.$on('$ionicView.enter', function(){...})
or cache:false
?
What is the real difference between each one?
$ionicView.enter
is an event that is broadcasted each time the selected view is activated.cache:false
means that the page will never be cached, and is therefore, reloaded completely each time.I personnaly try to avoid using cache false as it as bad performances but has side effects as your controller won't be initialised again when you are back on it.
Instead, when I enter a view, I user
$ionicView.enter
or$ionicView.afterEnter
to trigger several actions for page to completly finished the loading.I really enjoyed this Q & A:
ui.router not reloading controller
Where the Bipin Bhandari nicely summarizes the options we have with ionic caching mechanism
cache: false
,$ionicConfigProvider.views.maxCache(0)
;So, with caching in place, controller will be executed just once:
We can hook on these events... to do some "always stuff" with this controller