【发布时间】:2019-01-08 10:19:54
【问题描述】:
我按照本教程创建了一个带有侧边菜单和标签的 ionic 3 应用程序link
一开始一切正常,这是我的应用程序:image1
这是我的 app.component.ts 的代码:
export interface PageInterface {
title: string;
name: string;
component: any;
icon: string;
index?: number;
tabName?: string;
tabComponent?: any;
}
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage: any = TabsPage;
pages: PageInterface[] = [
{ title: 'Home', name: 'HomePage', component: HomePage, tabComponent: HomePage, index: 0, icon: 'home' },
{ title: 'Demandes', name: 'DemandesPage', component: DemandesPage, tabComponent: DemandesPage, index: 1, icon: 'body' },
{ title: 'Ajouter un trajet', name: 'AddTraject', component: AddtrajectPage, tabComponent:AddtrajectPage, index: 2, icon: 'create' },
{ title: 'Ajouter une demande', name: 'AddDemande', component: AdddemandePage, tabComponent:AdddemandePage, index: 3, icon: 'add' },
{ title: 'About', name: 'AboutPage', component: AboutPage, tabComponent: AboutPage, icon: 'people' },
{ title: 'Contact', name: 'ContactPage', component: ContactPage, tabComponent: ContactPage, icon: 'contacts' },
{ title: 'Special', name: 'SpecialPage', component: OtherPage, icon: 'shuffle' },
];
@ViewChild(Nav) nav: Nav;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
});
}
openPage(page: PageInterface) {
let params = {};
// The index is equal to the order of our tabs inside tabs.ts
if (page.index) {
params = { tabIndex: page.index };
}
// If tabs page is already active just change the tab index
if (this.nav.getActiveChildNavs().length && page.index != undefined) {
this.nav.getActiveChildNavs()[0].select(page.index);
} else {
// Tabs are not active, so reset the root page
// In this case: moving to or from SpecialPage
this.nav.setRoot(page.component, params);
}
}
isActive(page: PageInterface) {
// Again the Tabs Navigation
let childNav = this.nav.getActiveChildNavs()[0];
if (childNav) {
if (childNav.getSelected() && childNav.getSelected().root === page.tabComponent) {
return 'primary';
}
return;
}
// Fallback needed when there is no active childnav (tabs not active)
if (this.nav.getActive() && this.nav.getActive().name === page.name) {
return 'primary';
}
return;
}
}
而我的标签页只有四页,
<ion-tabs>
<ion-tab [root]="tab1Root" tabTitle="Trajets" tabIcon="car"></ion-tab>
<ion-tab [root]="tab2Root" tabTitle="Demandes" tabIcon="body"></ion-tab>
<ion-tab [root]="tab3Root" tabTitle="+ trajet" tabIcon="create"></ion-tab>
<ion-tab [root]="tab4Root" tabTitle="+ demande" tabIcon="add"></ion-tab>
</ion-tabs>
问题是,例如,当我单击位于侧面菜单而不是选项卡中的联系人时,我得到了联系页面但没有选项卡。 我想知道如何在所有页面中包含选项卡。请大家帮忙。
【问题讨论】:
标签: typescript ionic-framework