From 996c901ff9f24d0a93bba8eb9fdee943cc5150ad Mon Sep 17 00:00:00 2001 From: Martin Staffa Date: Tue, 7 Jun 2016 10:24:20 +0200 Subject: [PATCH] docs(changelog, guide/migration): mention rare BC for ngInclude See https://github.com/angular/angular.js/issues/13555#issuecomment-165118890 for detailed explanation. --- CHANGELOG.md | 38 ++++++++++++++++++++++++ docs/content/guide/migration.ngdoc | 47 +++++++++++++++++++++++++----- 2 files changed, 78 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d60748b30..2a3c71cc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -956,6 +956,44 @@ describe('$q.when', function() { [#11580](https://github.com/angular/angular.js/issues/11580), [#12234](https://github.com/angular/angular.js/issues/12234)) +## Breaking Changes + +- **ngInclude:** due to [3c6e8ce044446735eb2e70d0061db8c6db050289](https://github.com/angular/angular.js/commit/3c6e8ce044446735eb2e70d0061db8c6db050289), the `src` attribute of ngInclude no longer accepts an +expression that returns the result of `$sce.trustAsResourceUrl`. This will now cause an infinite digest: + +Before: +```html +
+``` + +```js +$scope.findTemplate = function(templateName) { + return $sce.trustAsResourceUrl(templateName); +}; +``` + +To migrate, either cache the result of `trustAsResourceUrl()`, or put the template url in the resource +whitelist in the `config()` function: + +After: + +```js +var templateCache = {}; +$scope.findTemplate = function(templateName) { + if (!templateCache[templateName]) { + templateCache[templateName] = $sce.trustAsResourceUrl(templateName); + } + + return templateCache[templateName]; +}; + +// Alternatively, use `$sceDelegateProvider.resourceUrlWhitelist()`: + +angular.module('myApp', []).config(function($sceDelegateProvider) { + $sceDelegateProvider.resourceUrlWhitelist(['self', 'https://example.com/**']) +}); +``` + # 1.3.17 tsktskskly-euouae (2015-07-06) diff --git a/docs/content/guide/migration.ngdoc b/docs/content/guide/migration.ngdoc index 3e4970b93..dafa3d029 100644 --- a/docs/content/guide/migration.ngdoc +++ b/docs/content/guide/migration.ngdoc @@ -284,7 +284,7 @@ angular.module('myApp').directive('form', function() { }); ``` -## Templating (`ngRepeat`, `$compile`) +## Templating (`ngRepeat`, `$compile`, `ngInclude`) ### ngRepeat @@ -316,6 +316,45 @@ returning an object from a controller constructor function will now override the controllerAs method will no longer get the this reference, but the returned object. +### ngInclude: +Due to [3c6e8ce044446735eb2e70d0061db8c6db050289](https://github.com/angular/angular.js/commit/3c6e8ce044446735eb2e70d0061db8c6db050289), the `src` attribute of ngInclude no longer accepts an +expression that returns the result of `$sce.trustAsResourceUrl`. This will now cause an infinite digest: + +Before: +```html +
+``` + +```js +$scope.findTemplate = function(templateName) { + return $sce.trustAsResourceUrl(templateName); +}; +``` + +To migrate, either cache the result of `trustAsResourceUrl()`, or put the template url in the resource +whitelist in the `config()` function: + +After: + +```js +var templateCache = {}; +$scope.findTemplate = function(templateName) { + if (!templateCache[templateName]) { + templateCache[templateName] = $sce.trustAsResourceUrl(templateName); + } + + return templateCache[templateName]; +}; + +// Alternatively, use `$sceDelegateProvider.resourceUrlWhitelist()`, which means you don't +// have to use `$sce.trustAsResourceUrl()` at all: + +angular.module('myApp', []).config(function($sceDelegateProvider) { + $sceDelegateProvider.resourceUrlWhitelist(['self', 'https://example.com/templates/**']) +}); +``` + + ## Cookies (`ngCookies`) 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 delegates calls. - - ## Server Requests (`$http`) Due to [5da1256](https://github.com/angular/angular.js/commit/5da1256fc2812d5b28fb0af0de81256054856369), @@ -386,8 +423,6 @@ $http.get(url, { ``` - - ## Filters (`filter`, `limitTo`) ### `filter` filter @@ -405,8 +440,6 @@ Now, instead of returning empty object/array, it returns unchanged input. - - # Migrating from 1.2 to 1.3 ## Controllers