2
votes

I am working in ionic when i install application in android device the hardware back button was not working, after some R & D i got solution to register back button i have done it. but my problem is when select option popover is open and i press back button then it dismiss the popover that's OK but when i want to reopen select option after pressing hardware back button i'm unable to open it. registering back button uses some condition to check active portals and dismiss the active portal if any found. but it does not allow to open select option again. can anyone help me to solve this issue? my code is below...

platform.ready().then(() => {
      // this.config.pullVersion();
      let ready = true;


      // to handle hardware back button in android
      platform.registerBackButtonAction(() => {
        console.log("Back button action called");

        let activePortal = ionicApp._loadingPortal.getActive() ||
          ionicApp._modalPortal.getActive() ||
          ionicApp._toastPortal.getActive() ||
          ionicApp._overlayPortal.getActive();

          let view = this.navCtrl.getActive();
        if (activePortal) {

           ready = false;
            activePortal.dismiss();
            activePortal.onDidDismiss(() => { ready = true; });

            console.log("handled with portal");
            return;

        }

        if (menuCtrl.isOpen()) {
          menuCtrl.close();

          console.log("closing menu");
          return;
        }

        if (this.navCtrl.canGoBack()) {

           this.navCtrl.pop();
            console.log("poping back");

          return;
        } else {
          console.log("exiting from app");
           platform.exitApp();
            console.log("poping back");

        }

      }, 1);
    });

and select-option

<ion-select interface="popover" [disabled]="isStarted" [(ngModel)]="routeName" class="custom-option-btn" (ionChange)="optionsFn();">
            <ion-option value="" selected disabled>select Route</ion-option>
            <ion-option *ngFor="let cg of routeData;let idx = index" [value]="cg">{{cg.routeName}} </ion-option>
          </ion-select>

this got dismissed in back button event and does not open select option again

 ionicApp._overlayPortal.getActive()
1

1 Answers

1
votes

I've been searching a lot about this topic, and Ionic Team hasn't developed a solution for this yet (I know it's been 3 years now). It seems that the only way we have to dismiss an ion-select is by using the 'cancel' button inside the selector.

Any other way, using platform.backbutton, or anything in IonicApp module won't let you do what you need.

The only real solution i can think about is creating a new Modal, only for the select, and implement your own scroll and selectable items, and then use ModalController.dismiss() to dismiss the select, as if you were pressing cancel inside the ion-select.