Hey, I just checked, and even though its going to the grand parent view, its actually not popping off the stack of views, but instead going down the view. The reason I know this is because the back button remains (the grandparent view is the root view) and when I click the Back button, it takes me back to the grandchild view.
Really I want it to pop up 2 levels in the stack, not add the grand parent view as the child view, how can I achieve that?
Uhh no, I DO want to go back, the issue is its creating a new view with the grandparent view. I think its because I’m using “view.go()” while in the other case (where I go back only 1 view), I’m using goBack(). Maybe the navAction and navDirection are being able to deliver the hint to the navbar-header?
.service('goBackMany',function($ionicHistory){
return function(depth){
// get the right history stack based on the current view
var historyId = $ionicHistory.currentHistoryId();
var history = $ionicHistory.viewHistory().histories[historyId];
// set the view 'depth' back in the stack as the back view
var targetViewIndex = history.stack.length - 1 - depth;
$ionicHistory.backView(history.stack[targetViewIndex]);
// navigate to it
$ionicHistory.goBack();
}
})
And here is some code that looks for a specific stateId :
.service('returnToState', function($ionicHistory){
return function(stateName){
var historyId = $ionicHistory.currentHistoryId();
var history = $ionicHistory.viewHistory().histories[historyId];
for (var i = history.stack.length - 1; i >= 0; i--){
if (history.stack[i].stateName == stateName){
$ionicHistory.backView(history.stack[i]);
$ionicHistory.goBack();
}
}
}
})
So, just pass one of these in a dependency and it can be used thusly:
This is really useful. I have used your service but there seems to be a problem with hardware back button on it. The hardware back button still goes to previous state in history while the backbutton in nav bar works as expected. Any suggestions on how to fix it?
You can directly go to 2 or many parent state till to get end your stack of $ionicHistory and all you need to do is -->
use
–>> $ionicHistory.goBack(-2) [quote=“debnath, post:1, topic:16176, full:true”]
I have figured out how to go back one view to the parent when I click an item on the list: