Using cache view false for specific transition
10,510
Option 1) You can pass a state param like you did in $state.go('home',{cache: false});
and handle it in your controller's beforeEnter event. Remember to inject $stateParams into your controller.
angular.module('app.controllers', []).controller('HomeCtrl', function($scope, $stateParams) {
$scope.$on('$ionicView.beforeEnter', function(){
if ($stateParams.cache === false) {
// Do whatever you need, reload $scope data, etc
}
});
...
});
Furthermore, you'll need to add a description for your parameter in the router config. Pay attention to params: {cache: null}
:
$stateProvider.state('app.home', {
url: '/home',
params: { cache: null },
views: {
'menuContent': {
templateUrl: 'templates/home.html',
controller: 'HomeCtrl'
}
}
});
Option 2) If you don't mind to clear cache for all views, you can use:
$ionicHistory.clearCache().then(function(){
$state.go('home');
});
See: $ionicHistory.clearCache()
Related videos on Youtube
Author by
Ranjit
Updated on June 04, 2022Comments
-
Ranjit almost 2 years
I know this can false the cache in particular state or view
Disable cache within state provider
$stateProvider.state('myState', { cache: false, url : '/myUrl', templateUrl : 'my-template.html' })
Disable cache with an attribute
<ion-view cache-view="false" view-title="My Title!"> ... </ion-view>
But i need to false the cache from a specific view transition for example
$state.go('home',{cache: false});
here i have to false the home state cache, I tried this but not working yet