我对离子性还很陌生,在这一点上我很迷失:
我有以下html:
<ion-menu [content]="mainContent">
<ion-header>
<ion-toolbar>
<ion-title>
Menu
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content id="side-menu21">
<ion-list id="menu-list1">
<ion-item color="none" id="menu-list-item1" (click)="gotoTabPending();">
Pendientes
</ion-item>
<ion-item color="none" id="menu-list-item2" (click)="gotoTabDone();">
Realizadas
</ion-item>
<ion-item color="none" id="menu-list-item3" (click)="gotoTabAll();">
Todas
</ion-item>
</ion-list>
</ion-content>
</ion-menu>
<ion-nav #mainContent [root]="rootPage"></ion-nav>
调用以下三种方法:
gotoTabPending(){
this.navCtrl.push(PendingTasksPage);
this.menuCtrl.close();
}
gotoTabDone(){
this.navCtrl.push(DoneTasksPage);
this.menuCtrl.close();
}
gotoTabAll(){
this.navCtrl.push(AllTasksPage);
this.menuCtrl.close();
}
我正在尝试将这些方法合而为一,就像这样:
<ion-item color="none" id="menu-list-item3" (click)="gotoTab(AllTasksPage);">
gotoTab(param){
this.navCtrl.push(param);
this.menuCtrl.close();
}
我一直在做一些研究,但没有发现任何有用的东西。有什么办法吗?
预先感谢
答案 0 :(得分:0)
您可以执行此操作...
export interface PageInterface {
title: string;
name: string;
index?: any;
}
appPages: PageInterface[] = [
{ title: 'Pendientes', name: PendingTasksPage, index: 0 },
{ title: 'Realizadas', name: DoneTasksPage, index: 1 },
{ title: 'Todas', name: AllTasksPage, index: 2 },
];
gotoTab(x){
this.navCtrl.push(x.name);
this.menuCtrl.close();
}
<ion-menu [content]="mainContent">
<ion-header>
<ion-toolbar>
<ion-title>
Menu
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content id="side-menu21">
<ion-list id="menu-list1">
<ion-item *ngFor="let x of appPages" color="none" id="menu-list-item1" (click)="gotoTab(x);">
{{x.title}}
</ion-item>
</ion-list>
</ion-content>
</ion-menu>
<ion-nav #mainContent [root]="rootPage"></ion-nav>