Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In Ionic I can go back just using:

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

The question is how to go to the view before backView? Something like:

var backBackView = $ionicViewService.getView(-2);
backBackView && backBackView.go();
like image 451
alexpods Avatar asked Mar 15 '14 21:03

alexpods


3 Answers

After some experiments I ended with next solution:

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

It looks bad for me, but successfully resolves the problem. I hope this will help to someone.

Update: Now you could actually call

$ionicHistory.goBack(-2);

which is described in ionic's documentation.

like image 132
alexpods Avatar answered Sep 29 '22 21:09

alexpods


I've found the following to be the quickest way to go backwards when deep in a view stack:

$ionicHistory.goBack();

I believe you can call that multiple times in a loop to keep going back in the view history. Of course, you have to inject $ionicHistory in your controller.

like image 25
CyberFerret Avatar answered Sep 29 '22 20:09

CyberFerret


This is now available in nightlies using $ionicGoBack(amount) https://github.com/driftyco/ionic/commit/63a0834d63eb87b86238fccde4bf4e77f3540085

like image 21
Deminetix Avatar answered Sep 29 '22 22:09

Deminetix