【问题标题】:How can i enable device backbutton in ionic?如何在 ionic 中启用设备后退按钮?
【发布时间】:2018-04-05 02:28:35
【问题描述】:

我已经通过这样的后退按钮注册操作事件在某些条件下禁用了后退按钮:

    $ionicPlatform.registerBackButtonAction(function (event) {
    if (condition)
       {
       event.preventDefault();
       $ionicHistory.nextViewOptions({ disableBack: true });
       } 
    else
       {
       $ionicHistory.goBack();
       }
       }, 800);

那么现在我该如何再次启用该设备后退按钮? 因为它仍然被禁用并且也不会进入以前的视图。

【问题讨论】:

  • 您是否尝试注册后退按钮以退出应用程序?

标签: angularjs ionic-framework back-button


【解决方案1】:

你需要试试这个

var lastTimeBackPress = 0;
  var timePeriodToExit = 2000;

  platform.registerBackButtonAction(() => {
    // get current active page
    let view = this.nav.getActive();
    if (view.component.name == "HomePage") {
      //Double check to exit app                  
      if (new Date().getTime() - lastTimeBackPress < timePeriodToExit) {
        platform.exitApp(); //Exit from app
      } else {
        let toast = this.toastCtrl.create({
          message: 'Press back again to exit App',
          duration: 3000,
          position: 'bottom'
        });
        toast.present();
        lastTimeBackPress = new Date().getTime();
      }
    } else {
      // go to previous page
      this.nav.pop({});
    }
  });

希望对你有用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-21
    • 2019-09-01
    • 2019-08-11
    • 2018-02-04
    • 1970-01-01
    • 2020-05-27
    • 1970-01-01
    • 2020-01-28
    相关资源
    最近更新 更多