Introducing controller life cycle events
Compared to AngularJS, Ionic offers many life cycle events:
$scope.$on('$ionicView.loaded', function(){});
$scope.$on('$ionicView.unloaded', function(){});
$scope.$on('$ionicView.enter', function(){});
$scope.$on('$ionicView.leave', function(){});
$scope.$on('$ionicView.beforeEnter', function(){});
$scope.$on('$ionicView.beforeLeave', function(){});
$scope.$on('$ionicView.afterEnter', function(){});
$scope.$on('$ionicView.afterLeave', function(){});
These events are necessary if you want to have control over the view cache.
$ionicView.loaded
event, for instance, is triggered the first time a view is loaded. This event will not be triggered any longer while this view is cached, even if the user comes back to it. This is generally the event you would use to initiate variables the same way you do with $viewContentLoaded
event in AngularJS.
If you want to fetch data every time you enter a view, cached or not, you can use the
$ionicView.enter
event.
By using the right event at the right time, you can improve the usability of the application.
Regarding performance, using the cache view only impacts the size of the DOM. When a page is cached, all its watchers are disconnected and the page is therefore just some more DOM elements lying on your page waiting to be used again.
Regarding performance, using the cache view only impacts the size of the DOM. When a page is cached, all its watchers are disconnected and the page is therefore just some more DOM elements lying on your page waiting to be used again.
The size of the DOM matters to have a great user experience, but caching up to ten pages seems to work fine (of course, depending on what you load in your pages).
0 comments:
Post a Comment