Skip to content

Commit 263b434

Browse files
committed
docs($http): add a note about modifying data in transformRequest
Closes angular#12468
1 parent 3c86212 commit 263b434

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/ng/http.js

+9
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,15 @@ function $HttpProvider() {
550550
* the transformed value (`function(data, headersGetter, status)`) or an array of such transformation functions,
551551
* which allows you to `push` or `unshift` a new transformation function into the transformation chain.
552552
*
553+
* <div class="alert alert-warning">
554+
* **Note:** Angular does not make a copy of the `data` parameter before it is passed into the `transformRequest` pipeline.
555+
* That means changes to the data are not local to the transform function (since Javascript passes objects by reference).
556+
* For example, if you are calling `$http.get(url, $scope.myObject)`, and then modify the object's properties in a transformRequest
557+
* function, the changes will be reflected on the scope and in any templates where the object is data-bound.
558+
* If you are modifying properties, it is therefore recommended to make a copy of the data in the transform function,
559+
* or create new object to return.
560+
* </div>
561+
*
553562
* ### Default Transformations
554563
*
555564
* The `$httpProvider` provider and `$http` service expose `defaults.transformRequest` and

0 commit comments

Comments
 (0)