Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49186

Go to last state not working

$
0
0

@priteshpmehta wrote:

Hi all,

I have one abstract page (like master page) and two child pages i.e Page1 and Page2... I want whenever i click on device's back button then if i am on Page1 then app needs to be exit (Its working fine with following code) ... and whenever i am on Page2 then app needs to go back to previous page. i.e Page1.

following is my piece of code :

.state('main', {
    url: '/main',
    abstract: true,
    templateUrl: 'templates/Main.html',
    controller: 'mainController'
  })

  .state('main.Page1', {
    url: '/Page1',
    views: {
      'Page1-main': {
        templateUrl: 'templates/Page1.html',
        controller: 'mmPage1Controller'
      }
    }
  })

  .state('main.Page2', {
    url: '/Page2',
    views: {
      'Page2-main': {
        templateUrl: 'templates/Page2.html'
      }
    }
  })

.controller('mainController',['$scope', '$state', '$rootScope', '$cordovaNetwork', '$ionicPopup', '$ionicPlatform', '$ionicHistory', function ($scope, $state, $rootScope, $cordovaNetwork, $ionicPopup, $ionicPlatform, $ionicHistory) {

  $ionicPlatform.registerBackButtonAction(function (event) {

   if($state.current.name=="main.Page1"){
      navigator.app.exitApp();
    }
    else {
      $scope._last_State = $ionicHistory.backView().stateName;
      $state.go($scope._last_State, {}, {reload: false});
    }
  }, 100);
}])

Any help would be appreciated...
Thank you.

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 49186

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>