1.我的sidemenu在login以后才能側(cè)滑出來(lái)保礼,在程序啟動(dòng)的時(shí)候是禁止的:
<ion-menu type="push" [swipeEnabled]="false" [content]="content"></ion-menu>
【 [swipeEnabled]="false" 】就對(duì)了,如果想自己判斷的話信粮,就起一個(gè)變量捻悯。
例如:
[swipeEnabled]="isEnabled" 來(lái)進(jìn)行判斷。
2.我的sidemenu在登陸的時(shí)候北戏,會(huì)根據(jù)不同的用戶身份,來(lái)展示不同的pages漫蛔,
因?yàn)閟idemenu是在app.html里面寫(xiě)的嗜愈,所以程序一啟動(dòng)的時(shí)候,就執(zhí)行了莽龟。后面再選擇用戶的時(shí)候蠕嫁,已經(jīng)渲染pages的已經(jīng)執(zhí)行過(guò)了,就會(huì)很尷尬毯盈。
接下來(lái)就是解決的方法:
app.component.ts:
import { Events } from 'ionic-angular';
constructor(
private events: Events,
) {
this.events.subscribe('user:created', (isUser) => {
if (isUser) {
this.pages = [
{ title: 'xxx', component: xxx },
{ title: 'aaa', component: aaa },
{ title: 'bbb', component: bbb },
{ title: 'ccc', component: ccc },
{ title: 'ddd', component: ddd }
];
} else {
this.pages = [
{ title: 'xxx', component: xxx },
{ title: 'aaa', component: aaa },
{ title: 'bbb', component: bbb }
];
}
});
}
login.ts:
if (this.isUser) {
this.events.publish( 'user:created', true );
} else {
this.events.publish( 'user:created', false );
}