Problems Ionic Framework

Asked

Viewed 488 times

0

Well I’m having trouble with the back button, initially I thought the problem was in Ordova, but I identified that the problem is actually in 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 the following mistake is being made:

Uncaught Referenceerror: $ionicPlatform is not defined

I am placing this code inside a new document called functionAngular.js and add it at the end of the body. How should I inform this function ?

My problem:

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

Thanks in advance for the help.

  • Have you tried to define the $ionicPlatform ?

  • Define where ?

  • I tried to log in the normal way. However registerBaclButtonAction is not visible.

  • Example: .run(function($ionicPlatform, $ionicPopup) {..

1 answer

2


The solution to my problem was to adjust the angle module, in addition to initialize the function, with the final code being 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);

});
  • Define the $ionicPlatform did it work? If yes, change your answer and say that’s what solved

  • No, setting did not work, because the module was not added.

  • Then it would be better if you edit the question and put that changed the module.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.