2016-05-01 44 views
0

使用離子框架可以通過ion-nav-back-button和設備後退按鈕本身在移動設備中返回到以前狀態的兩種方式。返回離子框架時的觸發動作

當我點擊ion-nav-back-button並按設備後退按鈕時,我應該調用什麼功能才能回到之前的狀態?

回答

0

我認爲以下應提供你正在尋找

唯一的解決方案是,我不知道,如果這個解決方案將工作100%硬件後退按鈕上的所有設備....

   // run this function when either hard or soft back button is pressed 
      var doCustomBack = function() { 
      // your custom handler code here 
      ..... 
       //}); 

       $ionicHistory.goBack(); 
      }; 

      // override soft back 
      // framework calls $rootScope.$ionicGoBack when soft back button is pressed 
      var oldSoftBack = $rootScope.$ionicGoBack; 
      $rootScope.$ionicGoBack = function() { 
       doCustomBack(); 
      }; 
      var deregisterSoftBack = function() { 
       $rootScope.$ionicGoBack = oldSoftBack; 
      }; 

      // override hard back 
      // registerBackButtonAction() returns a function which can be used to deregister it 
      var deregisterHardBack = $ionicPlatform.registerBackButtonAction(
       doCustomBack, 101 
      ); 

      // cancel custom back behaviour 
      $scope.$on('$destroy', function() { 
       deregisterHardBack(); 
       deregisterSoftBack(); 
      }); 
+0

會嘗試這一點,並給予反饋 – desmondlee

0

試試這個

<ion-nav-back-button class="button-clear" 
    ng-click="myGoBack()"> 
    <i class="ion-arrow-left-c"></i> Back 
    </ion-nav-back-button> 

function MyCtrl($scope, $ionicHistory) { 
    $scope.myGoBack = function() { 
    $ionicHistory.goBack(); 
    }; 
} 
+0

沒有這個假設觸發僅當NAV-後退按鈕是點擊,而非移動設備的硬件後退按鈕? – desmondlee

+0

'ionic.bundle.js'已經覆蓋了後退按鈕的代碼 –