Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何在Ionic中禁用特定页面的硬件按钮_Angularjs_Cordova_Ionic Framework - Fatal编程技术网

Angularjs 如何在Ionic中禁用特定页面的硬件按钮

Angularjs 如何在Ionic中禁用特定页面的硬件按钮,angularjs,cordova,ionic-framework,Angularjs,Cordova,Ionic Framework,我已经为app.run()中的所有状态编写了$ionicPlatform.registerBackButtonAction。因此,当应用程序初始化它时,请为所有页面注册回按钮。现在,我想更改该页面控制器中特定页面的硬件回按钮功能。如何在不再次注册所有其他页面的情况下执行此操作 $ionicPlatform.registerBackButtonAction(function() { if ($state.current.name == 'app.homepage' || $sta

我已经为
app.run()
中的所有状态编写了
$ionicPlatform.registerBackButtonAction
。因此,当应用程序初始化它时,请为所有页面注册回按钮。现在,我想更改该页面控制器中特定页面的硬件回按钮功能。如何在不再次注册所有其他页面的情况下执行此操作

 $ionicPlatform.registerBackButtonAction(function() {
        if ($state.current.name == 'app.homepage' || $state.current.name == 'app.loginUser') {
            navigator.app.exitApp();
        } else if ($state.current.name == "app.contacts" || $state.current.name == 'app.carDocuments' || $state.current.name == 'app.tracking' || $state.current.name == 'app.logBook'|| $state.current.name == 'app.geofence' || $state.current.name == 'app.walktocar' || $state.current.name == 'app.dashboard' || $state.current.name == 'app.geofenceTest' || $state.current.name == 'app.settings' || $state.current.name == 'app.about' || $state.current.name == 'app.tripDetail' ||      $state.current.name == 'app.newTripDetail'|| $state.current.name == 'app.followMeTrack' || $state.current.name == 'app.followMe' || $state.current.name == 'app.maintainance' || $state.current.name == 'app.faultHistory' || $state.current.name == 'app.routeType'|| $state.current.name == 'app.poi') {
            if ($rootScope.isDeletePage == "true") {
                $rootScope.$broadcast('callOriginalView');
                $rootScope.isDeletePage = "false";
            } else {
                $ionicHistory.nextViewOptions({
                    disableBack: true
                });

                $state.go('app.homepage');
            }

        } else {
            $ionicHistory.goBack();
        }
    }, 100);

因此,如果我再次编写$ionicPlatform.registerBackButtonAction,那么我必须再次编写所有这些代码以进行注册。如何仅在其控制器中覆盖特定页面的后退按钮通常,我们不应覆盖默认操作,但如果您想更改其功能,请确保使用该按钮执行单个功能

  // Disable BACK button on home
  $ionicPlatform.registerBackButtonAction(function (event) {
    if($state.current.name=="app.home"){ // here instead of "app.home" mention state name of particular page
      //navigator.app.exitApp(); // this is for exiting app
      // write your code that you wish to do
      event.preventDefault() // do nothing
    }
    else if($state.current.name=="app.settings"){ 

      // write your code that you wish to do

    }
    else if($state.current.name=="app.contact"){ 

      // write your code that you wish to do

    }
    else {
      navigator.app.backHistory();
    }
  }, 100);

若您希望在每个页面中有不同的操作,那个么在服务中有一个函数,并通过传递类似回调函数的配置从不同的控制器调用它。因此,您无需在每个控制器中注册添加示例代码,但使用您的解决方案,它将覆盖其他页面,也将注册回Button,我也必须再次注册它们,假设特定状态为“app.settings”单击“上一步”按钮,我必须将其移动到主页,并且在应用程序加载期间,我已经在app.js中注册了此项。现在,我不想再次注册所有按钮选中“更新的答案”。我在应用程序初始化期间只写了一次这些条件,我没有一次又一次地注册它,但对于特定的控制器,我想覆盖if条件,不想重写所有这些if条件。在单个状态下,您想对backButton执行多少操作(