How to set Back View

I have created the sample app by ionic

start myApp sidemenu

I have added the below logs in AppCtrl Controller as

$scope.$on(’$ionicView.enter’, function(e) {
var path = $location.path();
console.log(‘path is ::’+path);
console.log(‘viewHistory is ::’+$ionicHistory.viewHistory());
console.log(‘currentView is ::’+$ionicHistory.currentView());
console.log(‘currentHistoryId is ::’+$ionicHistory.currentHistoryId());
console.log(‘currentTitle is ::’+$ionicHistory.currentTitle());
console.log(‘backView is ::’+$ionicHistory.backView());
console.log(‘backTitle is ::’+$ionicHistory.backTitle());
});

and started the application by ionic serve it gives the below console output.

path is ::/app/playlists
viewHistory is ::[object Object]
currentView is ::[object Object]
currentHistoryId is ::ion1
currentTitle is ::Playlists
backView is ::null
backTitle is ::null
path is ::/app/playlists
viewHistory is ::[object Object]
currentView is ::[object Object]
currentHistoryId is ::ion1
currentTitle is ::Playlists
backView is ::null
backTitle is ::null

path is ::/app/playlists/3
viewHistory is ::[object Object]
currentView is ::[object Object]
currentHistoryId is ::ion1
currentTitle is ::Playlist
backView is ::[object Object]
backTitle is ::Playlists

path is ::/app/playlists
viewHistory is ::[object Object]
currentView is ::[object Object]
currentHistoryId is ::ion1
currentTitle is ::Playlists
backView is ::null
backTitle is ::null

path is ::/app/playlists/3
viewHistory is ::[object Object]
currentView is ::[object Object]
currentHistoryId is ::ion1
currentTitle is ::Playlist
backView is ::null
backTitle is ::null

  1. When application load why the ionicView.enter fires two times?
  2. If i visited the playlists 3 item it set’s the backView. again by going back button to playlists it sets the backView to null. Now reselect the same menu ie. Playlists from side menu it don’t fire any ionicView.enter event.?
  3. After this If i visited the 3 item again it set’s the backView to null. which causes to not showing back button on playlists/3 screen. How can i set the backView on item tap?

Thanks,
Amol.

Hello, I know isn’t the most elegant solution, but it works :stuck_out_tongue:

controller('BackViewController", function($scope, $rootScope, $location) {
   $scope.goTo = function (view) {
      $rootScope.currentView = $location.path();
      $state.go(view);
})

 controller('OtherViewController", function($scope, $rootScope, $state) {
   $scope.goBack = function () {
      $state.go( $rootScope.currentView );
})

I hope it helps