我想在ionic2中創建側面菜單。但是,我不知道如何顯示和隱藏菜單內的選項。 我想在菜單中,登錄前和登錄後顯示一些選項。如何在側面菜單中顯示和隱藏頁面IONIC2
Before login After login
--------- ---------
Home Home
Login Myprofile
Logout
app.ts
pages: Array<{title: string, component: any}>;
pagess: Array<{title: string, component: any}>;
this.pages= [
{ title: 'Home', component: HomePage},
{ title: 'Login', component: LoginPage}
];
this.pagess = [
{ title: 'Home', component: HomePage},
{ title: 'Myprofile', component: MyprofilePage},
{ title: 'Logout', component: HomePage}
];
enableMenu(loggedIn: boolean) {
this.menu.enable(loggedIn, 'loggedInMenu');
this.menu.enable(!loggedIn, 'loggedOutMenu');
}
我不知道如何設置enableMenu
app.html
<ion-menu id="loggedOutMenu" [content]="content">
<ion-header>
<ion-toolbar>
<ion-title>Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<button menuClose ion-item *ngFor="let p of pages" (click)="openPage(p)">
{{p.title}}
</button>
</ion-list>
</ion-content>
</ion-menu>
<ion-menu id="loggedInMenu" [content]="content">
<ion-header>
<ion-toolbar>
<ion-title>Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<button menuClose ion-item *ngFor="let p of pagess " (click)="openPage(p)">
{{p.title}}
</button>
</ion-list>
</ion-content>
</ion-menu>
<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
login.ts(登錄是在檢查myphpfile)
login() {
this.api.getLogin(this.username, this.password).subscribe(
data => {
let loader = this.loadingCtrl.create({
content: "Please wait...",
duration: 1000
});
loader.present();
this.navCtrl.setRoot(HomePage);
},
err => {
let alert = this.alertCtrl.create({
title: 'Warning!',
subTitle: 'incorrect!',
buttons: ['OK']
});
alert.present();
}
);
}
如果您正在成功回撥使頁面視圖,如果你不登錄,那麼不要顯示使用'* ngIf'來實現此 –
登錄前有什麼用sidemenu? –
@varunaaruru登錄之前'setroot = home'和側面菜單有'home'' login'和登錄成功後''setroot = home'和側面菜單有'home''myprofile''註銷' – fongfuse