Logout and return to welcome view. ionicHistory

Hello,

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');
      })
    };
}])

But when I tap the button, It does nothing.

  `<button class="button button-block button-dark" ng-click="logout()" >Logout</button>`

Any ideas what is the problem?

place a console log to see if it’s reaches the function … so

$scope.logout = function(){
console.log("here");

my guesses are that the code inside

$ionicHistory.clearCache().then(function() {

is not fired … also place a console log in the reject function of $ionicHistory.clearCache() promise

It’s saying the next when I tap the button ( I mean inside of the code $ionicHistory.clearCache().then(function() {

$ionicHistory.clearCache(…) is undefined

is a very problematic function, googling for it reveals lots of forum threads and Github issues that it doesn’t work as expected etc.

Maybe this helps:

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();
});