This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Commit 97bbf86
fix($compile): don't trim white-space in attributes
This allows developers to use white-space in their attributes, for example as value for
input[type=radio], as a separator in ngList, or as a value in any custom directive binding.
It's also consistent with the HTML spec, which allows white-space in attributes, and consistent
with Angular2, which also allows white-space in attributes.
Fixes #5513
Fixes #14539
Closes #5597
BREAKING CHANGE:
White-space in attributes is no longer trimmed automatically. This includes leading and trailing
white-space, and attributes that are purely white-space.
To migrate, attributes that require trimming must now be trimmed manually.
A common cases where stray white-space can cause problems is when
attribute values are compared, for example in an $observer:
Before:
```
$attrs.$observe('myAttr', function(newVal) {
if (newVal === 'false') ...
});
```
To migrate, the attribute value should be trimmed manually:
```
$attrs.$observe('myAttr', function(newVal) {
if (newVal.trim() === 'false') ...
});
```
Note that `$parse` trims expressions automatically, so attributes with expressions (e.g. directive
bindings) are unlikely to be affected by stray white-space.1 parent 3ba29c4 commit 97bbf86
File tree
3 files changed
+15
-1
lines changed- src/ng
- test/ng
- directive
3 files changed
+15
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1893 | 1893 | | |
1894 | 1894 | | |
1895 | 1895 | | |
1896 | | - | |
| 1896 | + | |
1897 | 1897 | | |
1898 | 1898 | | |
1899 | 1899 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4725 | 4725 | | |
4726 | 4726 | | |
4727 | 4727 | | |
| 4728 | + | |
| 4729 | + | |
| 4730 | + | |
| 4731 | + | |
| 4732 | + | |
| 4733 | + | |
| 4734 | + | |
| 4735 | + | |
4728 | 4736 | | |
4729 | 4737 | | |
4730 | 4738 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
133 | 139 | | |
134 | 140 | | |
135 | 141 | | |
0 commit comments