重新加载appcomponent.ts,同时注销ionic3

问题描述:

我有一个基于用户类型的场景,我需要获得侧面菜单。我只能在第一次启动应用程序时才能实现此目的。注销后,即使键入用户更改sidemenu保持不变。任何人都可以为此提出解决方案吗?重新加载appcomponent.ts,同时注销ionic3

所以你的问题不是最明确的问题,你应该在你的代码中添加下一个问题。

从我的理解是,你有多个用户类型,并希望为他们每个人的特定菜单。

您可以在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); 
} 

相关链接:

+0

更好的解决方案可能是使用'MenuController'并通过该控制器启用/禁用菜单 – Ivaro18