[英]What is the difference between $ionicView.enter and cache:false
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
? 我正在开发一个视图,每次打开视图时都需要调用webservice的multiples方法,如果我使用
$scope.$on('$ionicView.enter', function(){...})
或者cache:false
?
What is the real difference between each one? 每个人之间真正的区别是什么?
I really enjoyed this Q & A: 我非常喜欢这个问答:
Where the Bipin Bhandari nicely summarizes the options we have with ionic caching mechanism Bipin Bhandari很好地总结了我们对离子缓存机制的选择
cache: false
, cache: false
, $ionicConfigProvider.views.maxCache(0)
; $ionicConfigProvider.views.maxCache(0)
禁用缓存; So, with caching in place, controller will be executed just once: 因此,在缓存到位后,控制器将只执行一次:
Views are cached to improve performance.
缓存视图以提高性能。 When a view is navigated away from, its element is left in the DOM, and its scope is disconnected from the $watch cycle.
当视图被导航离开时,其元素将保留在DOM中,并且其范围与$ watch循环断开连接。 When navigating to a view that is already cached, its scope is reconnected, and the existing element, which was left in the DOM, becomes active again.
导航到已缓存的视图时,其范围将重新连接,并且留在DOM中的现有元素将再次变为活动状态。
We can hook on these events... to do some "always stuff" with this controller 我们可以挂钩这些事件...用这个控制器做一些“总是东西”
$ionicView.enter
is an event that is broadcasted each time the selected view is activated. $ionicView.enter
是每次激活所选视图时广播的事件。
cache:false
means that the page will never be cached, and is therefore, reloaded completely each time. cache:false
表示页面永远不会被缓存,因此每次都会重新加载。
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. 相反,当我进入视图时,我使用
$ionicView.enter
或$ionicView.afterEnter
来触发页面的多个动作以完成加载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.