【发布时间】:2018-04-13 10:32:27
【问题描述】:
我创建了一个示例聊天应用程序,当用户登录时,应用程序将导航到一个标签页
<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>
当我通过
console.log(this.navCtrl.getActive().name);从标签中检查当前活动页面时,我得到undefined。你能告诉我为什么吗?当我通过单击标题
this.navCtrl.push('FriendsPage');中的应用程序图标导航到新页面时。在新页面中,当我打印当前活动页面名称时,它显示上一个页面名称“ChatPage”而不是“FriendsPage”
编辑:添加后退按钮操作
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");
}
}
}
})
在我的情况下,当用户从选项卡导航到 FriendsPage 并且按下硬件后退按钮时。在正常情况下,视图应该弹出。但我收到了警报消息。
this.generic.showAlertConfirm("Exit", "Do you want to exit the app?", this.onYesHandler, this.onNoHandler, "backPress");
请帮我解决这个问题。
感谢和问候
阿南德·拉杰
【问题讨论】:
-
请帮我解决这个问题
-
你在哪里使用
console.log(...)? -
在两个页面的构造函数中
标签: angular typescript ionic2