我有一个场景,根据用户类型,我需要获得侧菜单,只有当我们启动第一次time.After注销应用程序时,我才能做到这一点,即使用户更改的类型保持不变。有人能对此提出解决方案吗?
发布于 2017-08-30 10:47:13
因此,您的问题不是最明确的问题,在您的下一个问题,您应该添加到您的代码。
据我所知,您有多个用户类型,并且希望每个用户都有一个特定的菜单。
您可以在您的app.component.html中创建类似的内容
<ion-list *ngIf="user.role = 'admin'">
<!-- admin menu -->
</ion-list>
<ion-list *ngIf="user.role = 'default'">
<!-- default menu -->
</ion-list>甚至让它成为特定的项目
<ion-list>
<ion-item>Home</ion-item> <!-- all users -->
<ion-item *ngIf="user.role = 'admin'">Analytics</ion-item> <!-- admin only -->
</ion-list>现在我们需要跟踪用户角色本身。
import { Events } from 'ionic-angular';
....
export class AppComponent {
user: any = {role: 'default'}; //declare it or do something smarter with the menu
constructor(private events: Events) {
this.events.subscribe('user:changed', user => {
// will update the user and immediately change menu accordingly
this.user = user;
});
}
}然后在登录功能中:
login() {
let user = this.myApi.login(this.username, this.encryptedPass);
// will trigger the function from app.component.ts
this.events.publish('user:changed', user);
}有用的链接:
https://stackoverflow.com/questions/45957358
复制相似问题