AngularJS ng-switch instruction
Depending on the selected value of the corresponding portion of the display:
<div ng-switch="myVar"> <div ng-switch-when="w3big"> <h1>本教程</h1> <p>欢迎访问本教程</p> </div> <div ng-switch-when="google"> <h1>Google</h1> <p>欢迎访问Google</p> </div> <div ng-switch-when="taobao"> <h1>淘宝</h1> <p>欢迎访问淘宝</p> </div> <div ng-switch-default> <h1>切换</h1> <p>选择不同选项显示对应的值。</p> </div> </div>
Definition and Usage
ng-switch command to show or hide based on an expression corresponding parts.
Corresponding sub-elementng-switch-when order, if you choose to display matching selected, the other for the removal of a match.
You can set the default options by usingng-switch-default command, if circumstances do not match, the default option will be displayed.
grammar
<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>
</ Element>
<Element ng-switch-when = "value"> </ element>
<Element ng-switch-when = "value"> </ element>
<Element ng-switch-when = "value"> </ element>
<Element ng-switch-default> </ element>
</ Element>
<Form> element supports the property.
Parameter Value
value | description |
---|---|
expression | Expression will match the display does not match the item is removed. |