【问题标题】:closing ionic2 datetime popup, while pressing back button?关闭ionic2日期时间弹出窗口,同时按下后退按钮?
【发布时间】:2018-06-15 17:12:55
【问题描述】:

我正在使用 ionic2 ion-datetime,当我返回我的应用程序时,仍然显示日期选择器弹出窗口,尽管后页中没有 ion-data 时间标签。帮我删除按返回按钮时的弹出窗口

.html 文件

<ion-datetime id="dateofbirth" class="date" displayFormat="DD MMMM YYYY" [max]="maxDate" [min]="minDate">

.ts 文件(这里我写了一些自定义日期时间的逻辑)

let date: any = new Date(),
        maxYear = date.getFullYear() - 18, minYear = date.getFullYear() -65,
        month = date.getMonth() + 1, minDay:any = date.getDate(),
        this.minDate = minYear + "-" + month + "-" + minDay;
        this.maxDate = maxYear + "-" + month + "-" + maxDay;

【问题讨论】:

    标签: ionic2


    【解决方案1】:

    在您的 .ts 文件中使用以下代码,您的组件带有离子日期选择器

    ionViewWillLeave(){
            let backDrop: any = document.getElementsByTagName('ion-picker-cmp');
            if(backDrop.length > 0){
                for(let i = 0; i< backDrop.length; i++){
                    backDrop[i].style.display = 'none';
                }
            }
          }
    

    【讨论】:

    • 太棒了!欢迎@Ani
    • ionic-4的任何解决方案?
    【解决方案2】:

    按照以下方式修改您的 app.component.ts 文件,

      import { Platform, IonicApp } from 'ionic-angular';
    
      constructor(public platform: Platform, private ionicApp: IonicApp){}
    
      initializeApp() {
        this.platform.ready().then(() => {
          //back button handle
          this.platform.registerBackButtonAction(() => {
            let activePortal = this.ionicApp._loadingPortal.getActive() ||
              this.ionicApp._modalPortal.getActive() ||
              this.ionicApp._toastPortal.getActive() ||
              this.ionicApp._overlayPortal.getActive();
    
            if (activePortal) {
              activePortal.dismiss();
            }
          });
        });
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多