Problem with clicking a new page from ion tabs in ionic2

I created a sample chat application in which when a user logs in, the application will go to the tab page

 <ion-tabs tabsPlacement="top" color="header" tabsHighlight=true>
  <ion-tab [root]="tab1" tabTitle="Chats" tabIcon="chatbubbles"></ion-tab>
  <ion-tab [root]="tab2" tabTitle="Groups" tabIcon="contacts"></ion-tab>
  <ion-tab [root]="tab3" tabTitle="Profile" tabIcon="contact"></ion-tab>
</ion-tabs>

enter image description here

  • when I check the current active page on the tabs on console.log(this.navCtrl.getActive().name);, I get undefined. Could you tell me why?

  • When I go to a new page, click the app icon from the title this.navCtrl.push('FriendsPage');. On a new page, when I print the current name of the active page, the name of the previous page " ChatPage" instead of " FriendsPage" is displayedenter image description here

Edit: Added tilt action

      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();
    } else {
      if (this.nav.canGoBack()) {
        this.nav.pop();
      } else {
        if (this.nav.getActive().name === "LoginPage"||this.nav.getActive().name === "SignupPage") {
          this.platform.exitApp();
        }else {
          this.generic.showAlertConfirm("Exit", "Do you want to exit the app?", this.onYesHandler, this.onNoHandler, "backPress");
        }
      }
    }
  })

In my case, when the user navigates to the Friends tab from the tabs and the hardware submarine is pressed. In a normal case, a view should appear. But I get a warning.

this.generic.showAlertConfirm("Exit", "Do you want to exit the app?", this.onYesHandler, this.onNoHandler, "backPress");

, .

+1
1

, , , . .

app.component.ts :

import {  App } from 'ionic-angular';
constructor(private app: App){
}
ngAfterViewInit() { 
    this.app.getActiveNav().viewWillEnter.subscribe(event => {
      console.log("current page", event.id);  <== Here is what you need
    })
}

viewWillEnter . .

0

All Articles