sairam
sairam

Reputation: 309

ionic how to stop back button action not to go to previous state or screen?

I have a custom overlay screen is coming in controller and on clicking on hardware back button. I just want to dismiss the overlay that is there on top level of the controller.

But I am facing the problem that I am able to broadcast a message to dismiss the overlay. At the same time it is dismissing the controller and going back to the previous screen. I don't want that action. I just need to dismiss my custom overlay.

I am using registerBackButtonAction and giving prority of 101 still not getting resolved. Can anyone help me on this to dismiss only the overlay and still leave it in the same controller? I don't want to go back to previous controller.

Upvotes: 0

Views: 294

Answers (1)

Mohan Gopi
Mohan Gopi

Reputation: 7724

check this out link

//Handling device backbutton:

  $ionicPlatform.registerBackButtonAction(function(e) {
    //do your stuff
    if($state.current.name=="login") {
        console.log(e);
     e.preventDefault();
     alert('login');
     //navigator.app.exitApp();
    }
    else{

      $ionicHistory.goBack();
    }

    }, 101);

Upvotes: 1

Related Questions