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

Commit ed22d2f

Browse files
committed
docs(changelog, guide/Migration): add info about $sce BC in 1.7
Closes #16593 Closes #16622
1 parent a5cfa88 commit ed22d2f

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

CHANGELOG.md

+31-2
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ This in turn affects how dirty checking treats objects that prototypally
448448
inherit from `Array` (e.g. MobX observable arrays). AngularJS will now
449449
be able to handle these objects better when copying or watching.
450450

451-
### **$sce** due to:
452-
- **[1e9ead](https://github.com/angular/angular.js/commit/1e9eadcd72dbbd5c67dae8328a63e535cfa91ff9)**: handle URL sanitization through the `$sce` service
451+
### **$sce** :
452+
- due to **[1e9ead](https://github.com/angular/angular.js/commit/1e9eadcd72dbbd5c67dae8328a63e535cfa91ff9)**: handle URL sanitization through the `$sce` service
453453

454454
If you use `attrs.$set` for URL attributes (a[href] and img[src]) there will no
455455
longer be any automated sanitization of the value. This is in line with other
@@ -463,6 +463,35 @@ Note that values that have been passed through the `$interpolate` service within
463463
`URL` or `MEDIA_URL` will have already been sanitized, so you would not need to sanitize
464464
these values again.
465465

466+
- due to **[1e9ead](https://github.com/angular/angular.js/commit/1e9eadcd72dbbd5c67dae8328a63e535cfa91ff9)**: handle URL sanitization through the `$sce` service
467+
468+
binding `trustAs()` and the short versions (`trustAsResourceUrl()` et al.) to
469+
`ngSrc`, `ngSrcset`, and `ngHref` will now raise an infinite digest error:
470+
471+
```js
472+
$scope.imgThumbFn = function(id) {
473+
return $sce.trustAsResourceUrl(someService.someUrl(id));
474+
};
475+
```
476+
477+
```html
478+
<img ng-src="{{imgThumbFn(imgId)}}">
479+
```
480+
This is because the `$interpolate` service is now responsible for sanitizing
481+
the attribute value, and its watcher receives a new object from `trustAs()`
482+
on every digest.
483+
To migrate, compute the trusted value only when the input value changes:
484+
485+
```js
486+
$scope.$watch('imgId', function(id) {
487+
$scope.imgThumb = $sce.trustAsResourceUrl(someService.someUrl(id));
488+
});
489+
```
490+
491+
```html
492+
<img ng-src="{{imgThumb}}">
493+
```
494+
466495
### **orderBy** due to:
467496
- **[1d8046](https://github.com/angular/angular.js/commit/1d804645f7656d592c90216a0355b4948807f6b8)**: consider `null` and `undefined` greater than other values
468497

docs/content/guide/migration.ngdoc

+30
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,36 @@ Note that values that have been passed through the `$interpolate` service within
505505
`URL` or `MEDIA_URL` will have already been sanitized, so you would not need to sanitize
506506
these values again.
507507

508+
<hr/>
509+
510+
Due to **[1e9ead](https://github.com/angular/angular.js/commit/1e9eadcd72dbbd5c67dae8328a63e535cfa91ff9)**,
511+
binding {@link ng.$sce#trustAs trustAs()} and the short versions
512+
({@link ng.$sce#trustAsResourceUrl trustAsResourceUrl()} et al.) to
513+
{@link ng.ngSrc}, {@link ng.ngSrcset}, and {@link ng.ngHref} will now raise an infinite digest error:
514+
515+
```js
516+
$scope.imgThumbFn = function(id) {
517+
return $sce.trustAsResourceUrl(someService.someUrl(id));
518+
};
519+
```
520+
521+
```html
522+
<img ng-src="{{imgThumbFn(imgId)}}">
523+
```
524+
This is because {@link ng.$interpolate} is now responsible for sanitizing
525+
the attribute value, and its watcher receives a new object from `trustAs()`
526+
on every digest.
527+
To migrate, compute the trusted value only when the input value changes:
528+
529+
```js
530+
$scope.$watch('imgId', function(id) {
531+
$scope.imgThumb = $sce.trustAsResourceUrl(someService.someUrl(id));
532+
});
533+
```
534+
535+
```html
536+
<img ng-src="{{imgThumb}}">
537+
```
508538

509539

510540
<a name="migrate1.6to1.7-ng-filters"></a>

0 commit comments

Comments
 (0)