1.我的sidemenu在login以后才能侧滑出来,在程序启动的时候是禁止的:
<ion-menu type="push" [swipeEnabled]="false" [content]="content"></ion-menu>
【 [swipeEnabled]="false" 】就对了,如果想自己判断的话,就起一个变量。
例如:
[swipeEnabled]="isEnabled" 来进行判断。
2.我的sidemenu在登陆的时候,会根据不同的用户身份,来展示不同的pages,
因为sidemenu是在app.html里面写的,所以程序一启动的时候,就执行了。后面再选择用户的时候,已经渲染pages的已经执行过了,就会很尴尬。
接下来就是解决的方法:
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 );
}
网友评论