Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
my data:

roleName: string

this.roleName='GC';

I want to display the some div based on the role.
help me with *ngIf syntax

What I have tried:

*ngIf="roleName =='GC' || roleName =='GCDR'"


*ngIf="roleName !=='GC' || roleName !=='GCDR'"
Posted
Updated 28-Jan-21 7:38am

You could achieve this using following code:

HTML
<div *ngIf="roleName === 'GC'">
    You're a GC user...
</div>
<div *ngIf="roleName === 'GCDR'">
    You're a GCDR user...
</div>


You could also achieve the same using ngSwitch directive:
HTML
<div [ngSwitch]="roleName">  
    <div *ngSwitchCase="'GC'">You're a GC user...</div>  
    <div *ngSwitchCase="'GCDR'">You're a GCDR user...</div>  
    <div *ngSwitchDefault>You're a unknown user ...</div>
</div>
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900