0

I'm new to this theme ionic. I read in several places I researched it does not work for me.

I would like to know how to do that when a person Press the button "back" of the cell not redirected to a previous state or to another view. I want that when the button is pressed "back" button of the Cell nothing happens.

I tried with this code, but it is the same thing happening, the button "back" my android device redirects me to another view of my application

$ionicPlatform.onHardwareBackButton(function() {
 event.preventDefault();
 event.stopPropagation();
 alert('nothing');
});

I'm putting my code, in this part, I'm not sure if it's the right place:

angular.module('app', ['ionic'])

.run(function($ionicPlatform) {

 $ionicPlatform.onHardwareBackButton(function() {
 event.preventDefault();
 event.stopPropagation();
 alert('nothing');
});

$ionicPlatform.ready(function() {

if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {  
.
.
.   

4 Answers4

0

You can hide it

ion-view title=""  hide-nav-bar="true">  
SAMUEL OSPINA
  • 321
  • 2
  • 9
0

You can achieve this with Javascript using Phonegap's Event API

document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown(e) {
  e.preventDefault();
}

Ref.

Community
  • 1
  • 1
solimanware
  • 2,952
  • 4
  • 20
  • 40
0

It looks that you will have to completely overide the back button functionality. To do this replace your current code with this one:

 $ionicPlatform.registerBackButtonAction(function(e){
    //do your stuff
    e.preventDefault();
    return false;
  },101);

Answer is mentioned in Ionic forum

Sarantis Tofas
  • 5,097
  • 1
  • 23
  • 36
0

This is what worked for me.

 .run(['$rootScope', '$ionicPlatform','$state',
        function($rootScope, $ionicPlatform,$state){    
        $ionicPlatform.registerBackButtonAction(function(e){

        e.preventDefault();
        return false;
      },101);

    }])
nabin
  • 687
  • 4
  • 13