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

Commit a2c1675

Browse files
committed
docs(guide/interpolation): add known issue (do not change the content of interpolated strings)
Closes #12813 Closes #14825
1 parent 951acb1 commit a2c1675

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

docs/content/guide/interpolation.ngdoc

+15-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ would be lost, because the browser ignores the attribute value.
4646
In the following example, the interpolation information would be ignored and the browser would simply
4747
interpret the attribute as present, meaning that the button would always be disabled.
4848

49-
```html
49+
```html
5050
Disabled: <input type="checkbox" ng-model="isDisabled" />
5151
<button disabled="{{isDisabled}}">Disabled</button>
5252
```
@@ -58,7 +58,7 @@ For this reason, Angular provides special `ng`-prefixed directives for the follo
5858
These directives take an expression inside the attribute, and set the corresponding boolean attribute
5959
to true when the expression evaluates to truthy.
6060

61-
```html
61+
```html
6262
Disabled: <input type="checkbox" ng-model="isDisabled" />
6363
<button ng-disabled="isDisabled">Disabled</button>
6464
```
@@ -115,6 +115,19 @@ can be used with `ngAttr` instead. The following is a list of known problematic
115115
- **type** in `<button>` in Internet Explorer 11 (see [issue 14117](https://github.com/angular/angular.js/issues/5025))
116116
- **value** in `<progress>` in Internet Explorer = 11 (see [issue 7218](https://github.com/angular/angular.js/issues/7218))
117117

118+
## Known Issues
119+
120+
### Dynamically changing an interpolated value
121+
122+
You should avoid dynamically changing the content of an interpolated string (e.g. attribute value
123+
or text node). Your changes are likely to be overwriten, when the original string gets evaluated.
124+
This restriction applies to both directly changing the content via JavaScript or indirectly using a
125+
directive.
126+
127+
For example, you should not use interpolation in the value of the `style` attribute (e.g.
128+
`style="color: {{ 'orange' }}; font-weight: {{ 'bold' }};"`) **and** at the same time use a
129+
directive that changes the content of that attributte, such as `ngStyle`.
130+
118131
### Embedding interpolation markup inside expressions
119132

120133
<div class="alert alert-danger">

src/ng/directive/ngClass.js

+5
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ function classDirective(name, selector) {
153153
* When the expression changes, the previously added classes are removed and only then are the
154154
* new classes added.
155155
*
156+
* @knownIssue
157+
* You should not use {@link guide/interpolation interpolation} in the value of the `class`
158+
* attribute, when using the `ngClass` directive on the same element.
159+
* See {@link guide/interpolation#known-issues here} for more info.
160+
*
156161
* @animations
157162
* | Animation | Occurs |
158163
* |----------------------------------|-------------------------------------|

src/ng/directive/ngStyle.js

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
* @description
99
* The `ngStyle` directive allows you to set CSS style on an HTML element conditionally.
1010
*
11+
* @knownIssue
12+
* You should not use {@link guide/interpolation interpolation} in the value of the `style`
13+
* attribute, when using the `ngStyle` directive on the same element.
14+
* See {@link guide/interpolation#known-issues here} for more info.
15+
*
1116
* @element ANY
1217
* @param {expression} ngStyle
1318
*

0 commit comments

Comments
 (0)