Im trying to create a controller that clear the cache of navigation in the app for make a Logout button.
My idea is cleaning the Session ID when I tap the Logout Button so I can go the Welcome View with the app “closed”.
Im trying to use $ionicHistory for this:
.controller('LogoutCtrl', ['$scope', '$state', '$ionicHistory', function($scope,$state,$ionicHistory) {
$scope.logout = function(){
$ionicHistory.clearCache().then(function() {
//now you can clear history or goto another state if you need
$ionicHistory.clearHistory();
$ionicHistory.nextViewOptions({ disableBack: true, historyRoot: true });
$state.go('welcome');
})
};
}])
This is working for me but i am not able to manage 2 time refresh. If i didn’t refresh whole page then i am not able to logout again . Want help .
$state.go(‘app.login’);
$scope.$on(’$ionicView.enter’, function(event, viewData) {
$ionicLoading.show({ template: ‘Logout Successfully!’, noBackdrop: true, duration: 2000 });
$rootScope.isLoggedIn=false;
window.localStorage.clear();
$rootScope.loginUser = “”;
console.log("in ionic view ");
$ionicHistory.clearCache();
$ionicHistory.nextViewOptions({ disableBack: true, historyRoot: true });
$window.location.reload();
});