2017-08-30 10 views

答えて

1

あなたの質問は最も明瞭な質問ではないので、次の質問でコードを追加する必要があります。

私が理解していることは、複数のユーザータイプがあり、それぞれに固有のメニューが必要なことです。

あなたは今、私たちはユーザーの役割自体を追跡する必要があなたの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

関連する問題