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();
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.
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.
This is now available in nightlies using $ionicGoBack(amount)
https://github.com/driftyco/ionic/commit/63a0834d63eb87b86238fccde4bf4e77f3540085
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With