$ionicView.enter 和 cache:false 有什么区别 [英] What is the difference between $ionicView.enter and cache:false
问题描述
我正在开发一个视图,每次打开视图时都需要调用 webservice 的多个方法,我应该使用 $scope.$on('$ionicView.enter', function(){...})
还是 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
?
每一个之间的真正区别是什么?
What is the real difference between each one?
推荐答案
我真的很喜欢这个 Q &答:
I really enjoyed this Q & A:
Bipin Bhandari 很好地总结了我们使用离子缓存机制的选项
Where the Bipin Bhandari nicely summarizes the options we have with ionic caching mechanism
- 通过
cache: false
避免缓存, - 使用
$ionicConfigProvider.views.maxCache(0)
禁用缓存; - 或者保持缓存不变,让控制器只执行一次......同时在这些期间做一些聪明的事情 查看生命周期和事件
- avoid caching by
cache: false
, - disable caching with
$ionicConfigProvider.views.maxCache(0)
; - or keep caching as is, and let controller be executed only once ... while doing some smart stuff during these View LifeCycle and Events
因此,有了缓存,控制器将只执行一次:
So, with caching in place, controller will be executed just once:
缓存视图以提高性能.当一个视图被导航离开时,它的元素留在 DOM 中,它的作用域与 $watch 循环断开连接.当导航到已经缓存的视图时,它的作用域会重新连接,并且留在 DOM 中的现有元素再次变为活动状态.
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. 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.
我们可以钩住这些事件......用这个控制器做一些永远的事情"
We can hook on these events... to do some "always stuff" with this controller
这篇关于$ionicView.enter 和 cache:false 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!