Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 9396d55

Browse files
docs(ngSwitch): clarify that ngSwitch matches against string literals
Closes #5285
1 parent 82e97cf commit 9396d55

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Diff for: src/ng/directive/ngSwitch.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,26 @@
66
* @restrict EA
77
*
88
* @description
9-
* The ngSwitch directive is used to conditionally swap DOM structure on your template based on a scope expression.
10-
* Elements within ngSwitch but without ngSwitchWhen or ngSwitchDefault directives will be preserved at the location
9+
* The `ngSwitch` directive is used to conditionally swap DOM structure on your template based on a scope expression.
10+
* Elements within `ngSwitch` but without `ngSwitchWhen` or `ngSwitchDefault` directives will be preserved at the location
1111
* as specified in the template.
1212
*
1313
* The directive itself works similar to ngInclude, however, instead of downloading template code (or loading it
14-
* from the template cache), ngSwitch simply choses one of the nested elements and makes it visible based on which element
14+
* from the template cache), `ngSwitch` simply choses one of the nested elements and makes it visible based on which element
1515
* matches the value obtained from the evaluated expression. In other words, you define a container element
16-
* (where you place the directive), place an expression on the **on="..." attribute**
17-
* (or the **ng-switch="..." attribute**), define any inner elements inside of the directive and place
16+
* (where you place the directive), place an expression on the **`on="..."` attribute**
17+
* (or the **`ng-switch="..."` attribute**), define any inner elements inside of the directive and place
1818
* a when attribute per element. The when attribute is used to inform ngSwitch which element to display when the on
1919
* expression is evaluated. If a matching expression is not found via a when attribute then an element with the default
2020
* attribute is displayed.
2121
*
22+
* <div class="alert alert-info">
23+
* Be aware that the attribute values to match against cannot be expressions. They are interpreted
24+
* as literal string values to match against.
25+
* For example, **`ng-switch-when="someVal"`** will match against the string `"someVal"` not against the
26+
* value of the expression `$scope.someVal`.
27+
* </div>
28+
2229
* @animations
2330
* enter - happens after the ngSwitch contents change and the matched child element is placed inside the container
2431
* leave - happens just after the ngSwitch contents change and just before the former contents are removed from the DOM
@@ -30,6 +37,7 @@
3037
* <ANY ng-switch-default>...</ANY>
3138
* </ANY>
3239
*
40+
*
3341
* @scope
3442
* @priority 800
3543
* @param {*} ngSwitch|on expression to match against <tt>ng-switch-when</tt>.

0 commit comments

Comments
 (0)