How to close overlays of form when back button is pressed?

Friends,
When I click back button from a form with form overlay I get back page with that overlay. How it can dismiss. My code to handle back button on app.components.ts is

    this.platform.registerBackButtonAction(() => {
    if (backbutton == 0) { // handling clicking back button
      if (this.global1.navPage == this.rootPageToExitOn) {
        backbutton++;
        this.showToastExit("Press BACK button to Exit !");

        // try dismiss but fails
        this.loading.dismiss();
        this.loading = null;
      }
      else {
        if (this.global1.navPage == this.OnlineService) {
          if (this.global1.getnetwork()) {
            this.nav.pop();
            this.showToast("Online Network !");
          }
          else {
            this.showToast("Offline !");
            this.nav.pop();
          }
        }
        else {
          this.nav.pop();
        }        
      }
    }
    else {
      navigator['app'].exitApp();
    }
  });

Please advise

Thanks

Anes