From 0749eb44e52ae1a01cdb24a1e35b78f7c4b33e4b Mon Sep 17 00:00:00 2001 From: Martin Staffa Date: Wed, 24 Feb 2016 14:26:10 +0100 Subject: [PATCH] docs($http): add a note about modifying data in transformRequest Closes #12468 --- src/ng/http.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ng/http.js b/src/ng/http.js index a6a43bf575bc..26cf37792c1d 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -550,6 +550,15 @@ function $HttpProvider() { * the transformed value (`function(data, headersGetter, status)`) or an array of such transformation functions, * which allows you to `push` or `unshift` a new transformation function into the transformation chain. * + *
+ * **Note:** Angular does not make a copy of the `data` parameter before it is passed into the `transformRequest` pipeline. + * That means changes to the properties of `data` are not local to the transform function (since Javascript passes objects by reference). + * For example, when calling `$http.get(url, $scope.myObject)`, modifications to the object's properties in a transformRequest + * function will be reflected on the scope and in any templates where the object is data-bound. + * To prevent his, transform functions should have no side-effects. + * If you need to modify properties, it is recommended to make a copy of the data, or create new object to return. + *
+ * * ### Default Transformations * * The `$httpProvider` provider and `$http` service expose `defaults.transformRequest` and