为模态<ion-modal-view>禁用android后退按钮

时间:2015-10-20 16:07:41

标签: angularjs ionic-framework ionic ionic-view ionicpopup

我在离子视图中有以下模态:

<ion-view id="doctors" cache-view="false" view-title="Directorio médico"  ng-controller="DoctorsDirController as doctorsCtrl">
  <ion-content>
              <!-- stuff inside here -->
  </ion-content>  
    <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            When this modal is open disable android back button
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
    <script id="result-details.html" type="text/ng-template">
      <ion-modal-view id="result-details-modal">
        <ion-content>

        </ion-content>
      </ion-modal-view>
    </script>
</ion-view>

这是app.js中config内的父视图(医生)的状态:

 .config(function ($stateProvider, $urlRouterProvider, $ionicConfigProvider) {

      .state('doctors', {
        url: '/doctors',
        templateUrl: "templates/doctors.html"
  })

所以在app.js run里面我试过了:

  1. 禁用父视图的Android后退按钮
  2. 但是对于所有其他视图充当正常的后退按钮。
  3. 代码:

    .run(function ($ionicPlatform, $state) {$ionicPlatform.ready(function () {
    
    
        $ionicPlatform.registerBackButtonAction(function () {
          //if we are in doctors do nothing
          if ($state.current.url == "/doctors") {
            //do nothing
    
            //else if we are in dashboard exit app
          } else if ($state.current.name == "dashboard") {
            ionic.Platform.exitApp();
    
            //else normal back-button functionality
          } else {
            navigator.app.backHistory();
          }
        }, 100);
    
      })
    

    问题是当在“医生”内部调用模态时,它似乎与父母“医生”不同,我的安卓后退按钮覆盖不再起作用。

1 个答案:

答案 0 :(得分:0)

使用它来禁用模式中的android后退按钮:

$scope.modal.hardwareBackButtonClose = false;