Ionic Framework Problems

0

I have a problem with the back button, I initially thought that the problem was in the cordova, but I identified that the problem is actually in the ionic, looking on the internet I found the following code:

  // Disable BACK button on home
  $ionicPlatform.registerBackButtonAction(function (event) {
    if($state.current.name=="app.home"){
      navigator.app.exitApp();
    }
    else {
      navigator.app.backHistory();
    }
  }, 100);

But it is giving the following error:

  

Uncaught ReferenceError: $ ionicPlatform is not defined

I'm putting this code inside a new document called functionAngular.js and adding it to the end of body . How do I report this function?

My problem:

  

I'm wanting the back button of aparelho móvel not to exit the application on screens other than the home screen. The problem is that instead of doing this, it closes the application.

Thank you in advance for the help.

    
asked by anonymous 23.12.2015 / 12:11

1 answer

2

The solution to my problem was to adjust the angle module, in addition to initializing the function, with the final code remaining as the following code:

angular.module('ionic')

.run(function($ionicPlatform,$state,$ionicHistory){

 $ionicPlatform.registerBackButtonAction(function (event) {
    if($state.current.name=="app.home"){
      navigator.app.exitApp();
    }
    else {
       $ionicHistory.backHistory();
    }
  }, 100);

});
    
23.12.2015 / 13:40