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.
Top comments (0)