ngSwitchCase
- Similar to switch case in lot of programming languages
- If you want to compare the value of field or property against multiple values use
ngSwitchCase
NgSwitch
is actually a set of three, cooperating directives: NgSwitch
, NgSwitchCase
, and NgSwitchDefault
NgSwitch
is an attribute directive
- The
NgSwitchCase
and NgSwitchDefault
directives are structural directives
<ul class="nav nav-pills">
<li [class.active]="viewMode == 'map'"><a (click)="viewMode = 'map'">Map View</a>
<li [class.active]="viewMode == 'list'"><a (click)="viewMode = 'list'">List View</a>
</ul>
<div [ngSwitch]="viewMode">
<div *ngSwitchCase="'map'">Map View Content</div>
<div *ngSwitchCase="'list'">List View Content</div>
<div *ngSwitchDefault>Otherwise</div>
</div>