简体   繁体   English

$ ionicView.enter和cache:false之间有什么区别?

[英]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: 我非常喜欢这个问答:

ui.router not reloading controller ui.router不重新加载控制器

Where the Bipin Bhandari nicely summarizes the options we have with ionic caching mechanism Bipin Bhandari很好地总结了我们对离子缓存机制的选择

  1. avoid caching by cache: false , 避免缓存cache: false
  2. disable caching with $ionicConfigProvider.views.maxCache(0) ; 使用$ionicConfigProvider.views.maxCache(0)禁用缓存;
  3. or keep caching as is, and let controller be executed only once ... while doing some smart stuff during these View LifeCycle and Events 或者按原样保持缓存,让控制器只执行一次......同时在这些View LifeCycle和Events中做一些聪明的事情

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.

相关问题 如何调试$ ionicView.beforeEnter和$ ionicView.enter之间的时间 - How to debug time between $ionicView.beforeEnter and $ionicView.enter IONIC-无法访问$ ionicView.enter上的externalDataDirectory - IONIC - can't access externalDataDirectory on $ionicView.enter 从$ ionicView.enter上具有特定属性的所有角度元素中删除类 - Remove class from all angular elements with specific attributes on $ionicView.enter JavaScript中0/1和true / false之间有什么区别 - What is the difference between 0/1 and true/false in JavaScript CacheAPI中缓存存储和缓存Object有什么区别 - What Is The Difference Between Cache Storage and Cache Object in CacheAPI Boolean('')为false和Boolean(new String(''))有什么区别? - what is the difference between Boolean('') is false and Boolean(new String(''))? JavaScript 中的真假与真假有什么区别? - What is the difference between truthy and falsy with true and false in JavaScript? iframe.src属性中“javascript:”,“#”和“javascript:false”之间的区别是什么? - What is the difference between “javascript:”, “#”, and “javascript:false” in iframe.src attribute 同步和异步请求之间有什么区别? (异步=真/假) - What is the difference between a synchronous and an asynchronous request? (async=true/false) Ionic 2的$ on(“ $ ionicView.beforeEnter”)等效项是什么? - What is the equivalent of $on(“$ionicView.beforeEnter”) for Ionic 2?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM