Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 996c901

Browse files
committed
docs(changelog, guide/migration): mention rare BC for ngInclude
See angular#13555 (comment) for detailed explanation.
1 parent 6234cda commit 996c901

File tree

2 files changed

+78
-7
lines changed

2 files changed

+78
-7
lines changed

CHANGELOG.md

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

958958

959+
## Breaking Changes
960+
961+
- **ngInclude:** due to [3c6e8ce044446735eb2e70d0061db8c6db050289](https://github.com/angular/angular.js/commit/3c6e8ce044446735eb2e70d0061db8c6db050289), the `src` attribute of ngInclude no longer accepts an
962+
expression that returns the result of `$sce.trustAsResourceUrl`. This will now cause an infinite digest:
963+
964+
Before:
965+
```html
966+
<div ng-include="findTemplate('https://example.com/myTemplate.html')"></div>
967+
```
968+
969+
```js
970+
$scope.findTemplate = function(templateName) {
971+
return $sce.trustAsResourceUrl(templateName);
972+
};
973+
```
974+
975+
To migrate, either cache the result of `trustAsResourceUrl()`, or put the template url in the resource
976+
whitelist in the `config()` function:
977+
978+
After:
979+
980+
```js
981+
var templateCache = {};
982+
$scope.findTemplate = function(templateName) {
983+
if (!templateCache[templateName]) {
984+
templateCache[templateName] = $sce.trustAsResourceUrl(templateName);
985+
}
986+
987+
return templateCache[templateName];
988+
};
989+
990+
// Alternatively, use `$sceDelegateProvider.resourceUrlWhitelist()`:
991+
992+
angular.module('myApp', []).config(function($sceDelegateProvider) {
993+
$sceDelegateProvider.resourceUrlWhitelist(['self', 'https://example.com/**'])
994+
});
995+
```
996+
959997

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

docs/content/guide/migration.ngdoc

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ angular.module('myApp').directive('form', function() {
284284
});
285285
```
286286

287-
## Templating (`ngRepeat`, `$compile`)
287+
## Templating (`ngRepeat`, `$compile`, `ngInclude`)
288288

289289
### ngRepeat
290290

@@ -316,6 +316,45 @@ returning an object from a controller constructor function will now override the
316316
controllerAs method will no longer get the this reference, but the returned object.
317317

318318

319+
### ngInclude:
320+
Due to [3c6e8ce044446735eb2e70d0061db8c6db050289](https://github.com/angular/angular.js/commit/3c6e8ce044446735eb2e70d0061db8c6db050289), the `src` attribute of ngInclude no longer accepts an
321+
expression that returns the result of `$sce.trustAsResourceUrl`. This will now cause an infinite digest:
322+
323+
Before:
324+
```html
325+
<div ng-include="findTemplate('https://example.com/templates/myTemplate.html')"></div>
326+
```
327+
328+
```js
329+
$scope.findTemplate = function(templateName) {
330+
return $sce.trustAsResourceUrl(templateName);
331+
};
332+
```
333+
334+
To migrate, either cache the result of `trustAsResourceUrl()`, or put the template url in the resource
335+
whitelist in the `config()` function:
336+
337+
After:
338+
339+
```js
340+
var templateCache = {};
341+
$scope.findTemplate = function(templateName) {
342+
if (!templateCache[templateName]) {
343+
templateCache[templateName] = $sce.trustAsResourceUrl(templateName);
344+
}
345+
346+
return templateCache[templateName];
347+
};
348+
349+
// Alternatively, use `$sceDelegateProvider.resourceUrlWhitelist()`, which means you don't
350+
// have to use `$sce.trustAsResourceUrl()` at all:
351+
352+
angular.module('myApp', []).config(function($sceDelegateProvider) {
353+
$sceDelegateProvider.resourceUrlWhitelist(['self', 'https://example.com/templates/**'])
354+
});
355+
```
356+
357+
319358
## Cookies (`ngCookies`)
320359

321360
Due to [38fbe3ee](https://github.com/angular/angular.js/commit/38fbe3ee8370fc449b82d80df07b5c2ed2cd5fbe),
@@ -353,8 +392,6 @@ has been moved to `$cookies`, to which `$cookieStore` now simply
353392
delegates calls.
354393

355394

356-
357-
358395
## Server Requests (`$http`)
359396

360397
Due to [5da1256](https://github.com/angular/angular.js/commit/5da1256fc2812d5b28fb0af0de81256054856369),
@@ -386,8 +423,6 @@ $http.get(url, {
386423
```
387424

388425

389-
390-
391426
## Filters (`filter`, `limitTo`)
392427

393428
### `filter` filter
@@ -405,8 +440,6 @@ Now, instead of returning empty object/array, it returns unchanged input.
405440

406441

407442

408-
409-
410443
# Migrating from 1.2 to 1.3
411444

412445
## Controllers

0 commit comments

Comments
 (0)