Angular 2

Angular NgSwitch Directive

The NgSwitch directive lets you to insert different sets of elements into the document based on a specified value or expression.NgSwitch Directive resides inside CommonModule module, so you can import it as shown below

Angular NgSwitch Directive

How to use NgSwitch

In the below code, we are getting iterating over the items objects, to show the status of the current item we are using [ngSwith] expression.

In the above example based on item.done property value, the nested span elements will be added to DOM.

By Arjun

I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.

Leave a Reply

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