Angular 17 @switch, @case and @default Example

By Hardik Savani January 22, 2024 Category : Angular

Hello Artisan,

I will explain step by step tutorial angular 17 @switch example. This post will give you a simple example of angular 17 switch case example. We will look at an example of angular 17 @switch @case example. This article goes in detailed on angular 17 conditional @switch example. Alright, let’s dive into the details.

Angular provides conditional statements using ngSwitch, ngSwitchCase, and ngSwitchDefault but, Angular 17 changed the condition statement flow with new syntax. You can use @switch, @case, and @default for the switch case condition in angular 17. You can see one be one example with output and a new conditional statement.

Let's see the simple example code:


You can update the following code with the app.component.ts file:


import { Component } from '@angular/core';

import { CommonModule } from '@angular/common';


selector: 'app-root',

standalone: true,

imports: [CommonModule],

templateUrl: './app.component.html',

styleUrls: ['./app.component.css']


export class AppComponent {

type:number = 2;


Here, update the app.component.html file:


<div class="container">

<!-- Using @switch @case -->

@switch (type) {

@case (1) {



@case (2) {



@default {




<!-- Using ngSwitch with ngSwitchCase -->

<div [ngSwitch]="type">

<div *ngSwitchCase="1">One</div>

<div *ngSwitchCase="2">Two</div>

<div *ngSwitchDefault>Default</div>




You will see the following output:



I hope it can help you...