How to return to two view states (something like $ window.history.go (-2))?

In Ionic, I can only return with:

var backView = $ionicViewService.getBackView(); backView && backView.go(); 

The question is, how do I get to the view before the backView? Something like:

 var backBackView = $ionicViewService.getView(-2); backBackView && backBackView.go(); 
+7
javascript angularjs ionic-framework
source share
3 answers

After some experimentation, I ended up with the following solution:

 var backView = $scope.$viewHistory.views[$scope.$viewHistory.backView.backViewId]; $scope.$viewHistory.forcedNav = { viewId: backView.viewId, navAction: 'moveBack', navDirection: 'back' }; backView && backView.go(); 

This looks bad to me, but it solves the problem successfully. Hope this helps someone.

Update : now you can call

 $ionicHistory.goBack(-2); 

which is described in the ionic documentation .

+16
source share

I found the following to be the fastest way to go back when deep in the view stack:

 $ionicHistory.goBack(); 

I believe that you can call it several times in a loop to keep returning to your browsing history. Of course you need to inject $ ionicHistory into your controller.

+9
source share

Now it is available at night using $ionicGoBack(amount) https://github.com/driftyco/ionic/commit/63a0834d63eb87b86238fccde4bf4e77f3540085

+2
source share

All Articles