Skip to content

Commit d2b08a0

Browse files
committed
docs(changelog, guide/migration): add BC notes for observing unset attributes
Closes angular#11163
1 parent 43c4029 commit d2b08a0

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
@@ -313,8 +313,6 @@ the built-in pattern validator:
313313
```
314314

315315

316-
317-
318316
<a name="1.4.5"></a>
319317
# 1.4.5 permanent-internship (2015-08-28)
320318

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

25902588

2589+
## Breaking Changes
25912590

2591+
- **$observe:** Due to [531a8de7](https://github.com/angular/angular.js/commit/531a8de72c439d8ddd064874bf364c00cedabb11),
2592+
observers no longer register on undefined attributes. For example, if you were using `$observe` on
2593+
an absent optional attribute to set a default value, the following would not work anymore:
2594+
2595+
```html
2596+
<my-dir></my-dir>
2597+
```
2598+
2599+
```js
2600+
// link function for directive myDir
2601+
link: function(scope, element, attr) {
2602+
attr.$observe('myAttr', function(newVal) {
2603+
scope.myValue = newVal ? newVal : 'myDefaultValue';
2604+
})
2605+
}
2606+
```
2607+
2608+
Instead, check if the attribute is set before registering the observer:
2609+
2610+
```js
2611+
link: function(scope, element, attr) {
2612+
if (attr.myAttr) {
2613+
// register the observer
2614+
} else {
2615+
// set the default
2616+
}
2617+
}
2618+
```
25922619

25932620
<a name="1.3.0"></a>
25942621
# 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)