Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

AngularJS ng-switch Directive

AngularJS ng-switch Instruction

AngularJS Reference Manual AngularJS Reference Manual


Show the corresponding section based on the selected value:


Runoob Tutorial

欢迎访问Runoob Tutorial

Google

欢迎访问Google

淘宝

欢迎访问淘宝

切换

选择不同选项显示对应的值。

Try it »


Definition and Usage

ng-switch The directive shows or hides the corresponding section based on the expression.

The corresponding child elements use ng-switch-when directive. If it matches, the selected one is shown; the others that do not match are removed.

You can use ng-switch-default directive to set the default option. If nothing matches, the default option is shown.


Syntax

<

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

elements support this attribute.

Parameter value

Value Description
expression The expression causes matching items to be shown and non-matching items to be removed.

AngularJS Reference Manual AngularJS Reference Manual