How to manipulate a back button pointer to point to a previous-previous View

Scenario:
Todo List > New Todo Form > Todo Entry

Expectations:
When I go from Todo List to New Todo Form, the back button should go back to Todo List.
When I submit the New Todo Form, I should be taken to view the Todo Entry.
From the Todo Entry, the back button should go back to TodoList.

Actual Result:
When I hit the back button from Todo Entry, it would take me back to the New Todo Form.

Here’s the fix:

.controller('NewTodoCtrl', function($scope, $state, $ionicViewService) {

  $scope.createTodo = function() {
    // performing create tasks assigning the object `todo`
    // ...

    // get the this current view's previous view
    var todoList = $ionicViewService.getBackView();

    // assign it as the current view (as far as history is concerned)
    $ionicViewService.setNavViews(todoList.viewId); 

    // proceed to the next view
    $state.go('todo.view', {id: todo.id});
  };

})

New result:
When I submit the New Todo Form, I am taken to view the Todo Entry.
When I hit the back button from the Todo Entry, I am taken to the Todo List.

7 Likes

That is exactly what I was looking for.

Things have changed in ionic: $ionicViewService.getBackView() is deprecated ($ionicHistory.backView).

How can I achieve $ionicViewService.setNavViews(todoList.viewId); now?