DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,503 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Digamber Rawat
Digamber Rawat

Posted on • Originally published at positronx.io on

Angular 9|8 NgSwitch Directive Tutorial with Examples

The post Angular 8 NgSwitch Directive Tutorial with Examples appeared first on positronX.io.

In this Angular 8 tutorial, we’ll learn to work with NgSwitch directive. We’ll understand the ngSwitch structural directive with real-world examples. NgSwitch is a built-in Angular 8 template directive, and it works the same way as the JavaScript’s switch statement does. This directive helps in showing or hiding the templates based on the conditional statement.

To make the NgSwitch work declare the NgSwitch structural directive on the main HTML element. Inside the NgSwitch container define the *ngSwitchCase statement, the *ngSwitchCase statement refers to one of the possibility from the multiple possibilities tree. If one statement doesn’t match with the expression, it goes to another ngSwitchCase statement, and if it doesn’t match with the expression, then it shows the result from the element where a *ngSwitchDefault statement is defined.

Click here to read more

Top comments (0)

🌚 Life is too short to browse without dark mode