【发布时间】:2017-07-13 08:13:10
【问题描述】:
我想在 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和侧边菜单有homelogin登录成功后setroot=home和侧边菜单有homemyprofilelogout -
@MohanGopi 你有我的例子T-T
-
我想说的是,在用户登录或注册后保留菜单是一个好习惯,因为在这些页面中将不会使用侧边菜单。如果我错了,请纠正我跨度>
标签: angular typescript ionic-framework ionic2