<!--app.component.html--> <divclass="account-feature-container" > <ng-container [ngSwitch]="accountStatus"> <ng-container *ngSwitchCase="AccountStatus.CLOSED"> <p>This is a closed account</p> </ng-container> <ng-container *ngSwitchCase="AccountStatus.AUTHORIZED"> <p>This is an authorized account</p> </ng-container> <ng-container *ngSwitchCase="AccountStatus.NORMAL"> <p>This is an normal account</p> </ng-container> <p *ngSwitchDefault>This is the default branch</p> </ng-container> </div>
<divclass="use_built-in_control_flow"> @switch (accountStatus) { @case (AccountStatus.CLOSED) { <p>This is a closed account</p> } @case (AccountStatus.AUTHORIZED) { <p>This is an authorized account</p> } @case (AccountStatus.NORMAL) { <p>This is an normal account</p> } @default { <p>This is the default branch</p> } } </div>
Tips:
Remember to add the @default branch at the end, if no case matched, and no @default is provided, nothing will be rendered.
There is no fallthrough in the @switch directive, so you don’t need to add break or return in each @case branch.