How to implement the Angular switch case in Angular 5 ?

Switch case in angular is a combination of 3 directives
1. ngSwitch directive
2. ngSwitchCase directive
3. ngSwitchDefault directive

If we have display some Text Value for some key value then we can use this syntax. It is similar to C# switch statement.

Syntax for using Switch in Angular is like this

<div class="col-xs-6" [ngSwitch]="employee.department">
              <span *ngSwitchCase="1"> Help Desk </span>
              <span *ngSwitchCase="2"> HR </span>
              <span *ngSwitchCase="3"> IT </span>
              <span *ngSwitchCase="4"> Payroll </span>
              <span *ngSwitchDefault> N/A </span>

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.