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

Commit 2f61845

Browse files
committed
docs(changelog, guide/migration): mention rare BC for ngInclude
See #13555 (comment) for detailed explanation. Closes #13555
1 parent 297a791 commit 2f61845

File tree

2 files changed

+77
-6
lines changed

2 files changed

+77
-6
lines changed

CHANGELOG.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,44 @@ describe('$q.when', function() {
20432043
[#11580](https://github.com/angular/angular.js/issues/11580), [#12234](https://github.com/angular/angular.js/issues/12234))
20442044

20452045

2046+
## Breaking Changes
2047+
2048+
- **ngInclude:** due to [3c6e8ce044446735eb2e70d0061db8c6db050289](https://github.com/angular/angular.js/commit/3c6e8ce044446735eb2e70d0061db8c6db050289), the `src` attribute of ngInclude no longer accepts an
2049+
expression that returns the result of `$sce.trustAsResourceUrl`. This will now cause an infinite digest:
2050+
2051+
Before:
2052+
```html
2053+
<div ng-include="findTemplate('https://example.com/myTemplate.html')"></div>
2054+
```
2055+
2056+
```js
2057+
$scope.findTemplate = function(templateName) {
2058+
return $sce.trustAsResourceUrl(templateName);
2059+
};
2060+
```
2061+
2062+
To migrate, either cache the result of `trustAsResourceUrl()`, or put the template url in the resource
2063+
whitelist in the `config()` function:
2064+
2065+
After:
2066+
2067+
```js
2068+
var templateCache = {};
2069+
$scope.findTemplate = function(templateName) {
2070+
if (!templateCache[templateName]) {
2071+
templateCache[templateName] = $sce.trustAsResourceUrl(templateName);
2072+
}
2073+
2074+
return templateCache[templateName];
2075+
};
2076+
2077+
// Alternatively, use `$sceDelegateProvider.resourceUrlWhitelist()`:
2078+
2079+
angular.module('myApp', []).config(function($sceDelegateProvider) {
2080+
$sceDelegateProvider.resourceUrlWhitelist(['self', 'https://example.com/**'])
2081+
});
2082+
```
2083+
20462084

20472085
<a name="1.3.17"></a>
20482086
# 1.3.17 tsktskskly-euouae (2015-07-06)

docs/content/guide/migration.ngdoc

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ angular.module('myApp').directive('form', function() {
514514
});
515515
```
516516

517-
### Templating (`ngRepeat`, `$compile`)
517+
### Templating (`ngRepeat`, `$compile`, `ngInclude`)
518518

519519
#### ngRepeat
520520

@@ -545,6 +545,44 @@ Due to [62d514b](https://github.com/angular/angular.js/commit/62d514b06937cc7dd8
545545
returning an object from a controller constructor function will now override the scope. Views that use the
546546
controllerAs method will no longer get the this reference, but the returned object.
547547

548+
#### ngInclude
549+
Due to [3c6e8ce044446735eb2e70d0061db8c6db050289](https://github.com/angular/angular.js/commit/3c6e8ce044446735eb2e70d0061db8c6db050289), the `src` attribute of ngInclude no longer accepts an
550+
expression that returns the result of `$sce.trustAsResourceUrl`. This will now cause an infinite digest:
551+
552+
Before:
553+
```html
554+
<div ng-include="findTemplate('https://example.com/templates/myTemplate.html')"></div>
555+
```
556+
557+
```js
558+
$scope.findTemplate = function(templateName) {
559+
return $sce.trustAsResourceUrl(templateName);
560+
};
561+
```
562+
563+
To migrate, either cache the result of `trustAsResourceUrl()`, or put the template url in the resource
564+
whitelist in the `config()` function:
565+
566+
After:
567+
568+
```js
569+
var templateCache = {};
570+
$scope.findTemplate = function(templateName) {
571+
if (!templateCache[templateName]) {
572+
templateCache[templateName] = $sce.trustAsResourceUrl(templateName);
573+
}
574+
575+
return templateCache[templateName];
576+
};
577+
578+
// Alternatively, use `$sceDelegateProvider.resourceUrlWhitelist()`, which means you don't
579+
// have to use `$sce.trustAsResourceUrl()` at all:
580+
581+
angular.module('myApp', []).config(function($sceDelegateProvider) {
582+
$sceDelegateProvider.resourceUrlWhitelist(['self', 'https://example.com/templates/**'])
583+
});
584+
```
585+
548586

549587
### Cookies (`ngCookies`)
550588

@@ -583,8 +621,6 @@ has been moved to `$cookies`, to which `$cookieStore` now simply
583621
delegates calls.
584622

585623

586-
587-
588624
### Server Requests (`$http`)
589625

590626
Due to [5da1256](https://github.com/angular/angular.js/commit/5da1256fc2812d5b28fb0af0de81256054856369),
@@ -616,8 +652,6 @@ $http.get(url, {
616652
```
617653

618654

619-
620-
621655
### Filters (`filter`, `limitTo`)
622656

623657
#### `filter` filter
@@ -636,7 +670,6 @@ Now, instead of returning empty object/array, it returns unchanged input.
636670

637671

638672

639-
640673
## Migrating from 1.2 to 1.3
641674

642675
### Controllers

0 commit comments

Comments
 (0)