Issue with view caching

Hi,

I’m having an issue with the view cache. Not sure if i’m doing it wrong or it’s an issue with Ionic.

In ‘add grocery’ view, initially there are 2 groceries, pull down to fetch more groceries. It shows additional groceries appended to the list. Now, go back and visit ‘add grocery’ view again.

If view caching is enabled (by default, it is), then i should be seeing more than 2 groceries in the list, however, i see only 2 groceries. Am I missing something here?

http://embed.plnkr.co/vUlbDf3c4ywP5g3F8sWs/preview

Appreciate your help.
Sreekanth

Nope, no issue here, this is by default.

By default, when navigating, views that were recently visited are cached, and the same instance data and DOM elements are referenced when navigating back. However, when navigating back in the history, the “forward” views are removed from the cache. If you navigate forward to the same view again, it’ll create a new DOM element and controller instance. Basically, any forward views are reset each time. Set this config to true to have forward views cached and not reset on each load.

You can enable this by adding this config option.

 $ionicConfigProvider.views.forwardCache(true);

@mhartington Ah, I missed that one. Thank you for clarifying it.

Another thing, in ‘browse’ view (use sidemenu to go this view), when tapped on ‘go to shopping list’ button, it does $state.go(‘app.shoppinglist’), so view/state transitions to ‘shopping list’ view correctly, but there, it displays ‘back’ nav button at the top. I would not want to see the back button, just like in the case when ‘browse’ menu item is tapped in the side menu, it doesn’t show any ‘back’ button.

Why is it showing ‘back button’? How do I fix it?

Thanks again
Sreekanth

You can use $ionicHistory for this.

$ionicHistory.nextViewOptions({
     disableAnimate: false,
     disableBack: true,
     historyRoot: true
});

Thanks @mhartington . That fixes my issue.