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

Commit 48ad748

Browse files
committed
docs(changelog, guide/migration): add BC notes for observing unset attributes
Closes #11163
1 parent 341b834 commit 48ad748

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

CHANGELOG.md

+29-2
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,6 @@ the built-in pattern validator:
709709
```
710710

711711

712-
713-
714712
<a name="1.4.5"></a>
715713
# 1.4.5 permanent-internship (2015-08-28)
716714

@@ -2984,7 +2982,36 @@ We also added a documentation page focused on security, which contains some of t
29842982
[#9578](https://github.com/angular/angular.js/issues/9578), [#9751](https://github.com/angular/angular.js/issues/9751))
29852983

29862984

2985+
## Breaking Changes
29872986

2987+
- **$observe:** Due to [531a8de7](https://github.com/angular/angular.js/commit/531a8de72c439d8ddd064874bf364c00cedabb11),
2988+
observers no longer register on undefined attributes. For example, if you were using `$observe` on
2989+
an absent optional attribute to set a default value, the following would not work anymore:
2990+
2991+
```html
2992+
<my-dir></my-dir>
2993+
```
2994+
2995+
```js
2996+
// link function for directive myDir
2997+
link: function(scope, element, attr) {
2998+
attr.$observe('myAttr', function(newVal) {
2999+
scope.myValue = newVal ? newVal : 'myDefaultValue';
3000+
})
3001+
}
3002+
```
3003+
3004+
Instead, check if the attribute is set before registering the observer:
3005+
3006+
```js
3007+
link: function(scope, element, attr) {
3008+
if (attr.myAttr) {
3009+
// register the observer
3010+
} else {
3011+
// set the default
3012+
}
3013+
}
3014+
```
29883015

29893016
<a name="1.3.0"></a>
29903017
# 1.3.0 superluminal-nudge (2014-10-13)

docs/content/guide/migration.ngdoc

+30
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,36 @@ After:
584584
};
585585
});
586586

587+
- due to [531a8de7](https://github.com/angular/angular.js/commit/531a8de72c439d8ddd064874bf364c00cedabb11),
588+
`$observe` no longer registers on undefined attributes. For example, if you were using `$observe` on
589+
an absent optional attribute to set a default value, the following would not work anymore:
590+
591+
```html
592+
<my-dir></my-dir>
593+
```
594+
595+
```js
596+
// Link function for directive myDir
597+
link: function(scope, element, attr) {
598+
attr.$observe('myAttr', function(newVal) {
599+
scope.myValue = newVal ? newVal : 'myDefaultValue';
600+
})
601+
}
602+
```
603+
604+
Instead, check if the attribute is set before registering the observer:
605+
606+
```js
607+
link: function(scope, element, attr) {
608+
if (attr.myAttr) {
609+
// register the observer
610+
} else {
611+
// set the default
612+
}
613+
}
614+
```
615+
616+
587617

588618

589619

0 commit comments

Comments
 (0)