2017-02-20 10 views
1

こんにちは、私は、私は、ユーザAのみB1contentを見るためだけにA1content、ユーザーBを見たいと思っ意味一つの成分に少数のユーザー固有のコンテンツを追加したい角度2.Angular2異なるユーザーに1つのコンポーネントと異なる内容を表示させるにはどうすればよいですか?

でWebアプリケーションを作ることに取り組んでいますC-C1など。

また、ログインしているユーザーとゲスト(ログインしていないユーザー)のコンテンツを分離したいと考えています。

どうすればよいですか?私が知っている限り、保護されたコンテンツにはAuthGuardを使用し、特定のユーザーにはngIfを使用する必要があります。

答えて

0

NgSwitchを使用できますか? https://angular.io/docs/ts/latest/api/common/index/NgSwitch-directive.html

テンプレート

<div *ngFor="let item of listOfItems"> 
    <div [ngSwitch]="item.type"> 
    <div *ngSwitchCase="'A'"> 
     <h1>output A - {{ item.name }}</h1> 
    </div> 
    <div *ngSwitchCase="'B'"> 
     <h1>output B - {{ item.name }}</h1> 
    </div> 
    <div *ngSwitchCase="'C'"> 
     <h1>output C - {{ item.name }}</h1> 
    </div> 
    <div *ngSwitchDefault>output2</div> 
    </div> 
</div> 

成分

export class SomeComponent { 
    public listOfItems = [ 
    { 
     name: 'Adam', 
     type: 'C', 
    }, 
    { 
     name: 'Eve', 
     type: 'B', 
    }, 
    { 
     name: 'George', 
     type: 'A' 
    } 
    ]; 
    constuctor() {} 
} 
関連する問題