Angular NgSwitch Example | NgSwitch Directive In Angular 10/9/8

By Hardik Savani | March 30, 2020 | Category : Angular


Hi Dev,

This tutorial will give you example of angular ngSwitch condition example. This article goes in detailed on ngSwitch condition in angular example.

this example will help you ng switch condition in angular. Here you will learn *ngSwitch condition in angular example.

This article will give you simple example of ngSwitch condition in angular. You can easily use ng switch in angular 6, angular 7, angular 8, angular 9 and angular 10 example.

ngSwitch directive provide you to write simple switch case of javascript. you can see bellow simple example that will help you more:

src/app/app.component.ts

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

@Component({

selector: 'my-app',

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

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

})

export class AppComponent {

mySwitchVar = "one";

}

src/app/app.component.html

<h1>Angular NgSwitch Directive Example - ItSolutionstuff.com</h1>

<div [ngSwitch]="mySwitchVar">

<div *ngSwitchCase="'one'">

<p>Switch Case One</p>

</div>

<div *ngSwitchCase="'two'">

<p>Switch Case Two</p>

</div>

<div *ngSwitchCase="'three'">

<p>Switch Case Three</p>

</div>

<div *ngSwitchDefault>

<p>Switch Case Default</p>

</div>

</div>

I also posted for ng if else condition in angular. so visit on bellow link:

ngIf Else Condition in Angular

I hope it can help you...




Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: