What is the difference between $ionicView.enter and cache:false

前端 未结 2 676
臣服心动
臣服心动 2020-11-29 10:25

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(){...})

相关标签:
2条回答
  • 2020-11-29 10:57

    $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.

    0 讨论(0)
  • 2020-11-29 11:02

    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

    1. avoid caching by cache: false,
    2. disable caching with $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

    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. 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

    0 讨论(0)
提交回复
热议问题