onHardwareBackButton question


I would like use onHardwareBackButton method, but doesnt work this code:
This code is in one controller

`starter.controller('ViewCtrl', function($scope,$state,$ionicPlatform) {...`
        $ionicPlatform.onHardwareBackButton(function() {
            if($state.current.name == 'view') { //in console **view** the state name

It must have something to work? Thanks

in this view, i use a modal, when i open modal and tap on mobile back button, go to app.comp state, but why?
if modal close and tap mobile back button, exit the app…

// Disable BACK button on home
$ionicPlatform.registerBackButtonAction(function (event) {
if (true) { // your check here
if($ionicHistory.currentStateName() != ‘app.home’){
title: ‘System Warning’,
template: ‘Are you sure you want to exit?’
}).then(function (res) {
if (res) {
}, 100);

1 Like