If Else
aboutus.component.ts
export class AboutusComponent implements OnInit { showMsg: boolean = true; . . . }
aboutus.component.html
<p *ngIf='showMsg; else elseBlock'>aboutus works from If block!</p> <ng-template #elseBlock> <p>aboutus works from else block!</p> </ng-template>
Output
aboutus works from If block!
Switch Case
aboutus.component.ts
export class AboutusComponent implements OnInit { . . color : string = 'pink'; . . }
aboutus.component.html
<div [ngSwitch] = 'color'> <p *ngSwitchCase="'blue'">Its Blue Color</p> <p *ngSwitchCase="'red'">Its Red Color</p> <p *ngSwitchCase="'green'">Its Green Color</p> <p *ngSwitchDefault>Its Default Color</p> </div>
Output
Its Default Color