ngSwitch in Angular5

In this post, I am going to explain “How to use ngSwitch in Angular5”, ngSwitch used in angular same as other programming language. In this article I will be show example “How to use ngSwitch in Angular”.

ngSwitch

ngSwitch is actually comprised of two directives, an attribute directive and a structural directive. Its very similar to a switch statement in JavaScript and other programming languages, but in the template.

The ngSwitch directive lets you hide/show html element depending on expression

We can also define a default section, by using the ng-switch-default directive, to show a section if none of the other sections get a match.

Three things to keep in mind –ngSwitch, ngSwitchCase, ngSwitchDefault



Example:-

 

Thanks!!

Add a Comment

Your email address will not be published. Required fields are marked *