AngularJS ng-switch Directive


Show a segment of HTML, just in the event that it coordinates a certain value:

<div ng-switch="myVar">
  <div ng-switch-when="dogs">
    <p>Welcome to a universe of dogs.</p>
  <div ng-switch-when="tuts">
    <p>Learn from examples.</p>
  <div ng-switch-when="cars">
    <p>Read about cars.</p>
  <div ng-switch-default>
    <p>Select point from the dropdown, to switch the substance of this DIV.</p>
Try it yourself »

Definition and Usage

The ng-switch order gives you a chance to shroud/show HTML components contingent upon an expression.

Child components with the ng-switch-when order will be shown on the off chance that it gets a match, generally the component, and it's youngsters will be removed.

You can likewise characterize a default segment, by utilizing the ng-switch-default mandate, to demonstrate an area if non of alternate segments get a match.


<element ng-switch="expression">
  <element ng-switch-when="value"></element>
  <element ng-switch-when="value"></element>
  <element ng-switch-when="value"></element>
  <element ng-switch-default></element>

Supported by all HTML elements.

Parameter Values

Value Description
expression An articulation that will evacuate components with no match, and show components with a match.