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

Commit 0749eb4

Browse files
committed
docs($http): add a note about modifying data in transformRequest
Closes #12468
1 parent c900b9c commit 0749eb4

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 properties of `data` are not local to the transform function (since Javascript passes objects by reference).
556+
* For example, when calling `$http.get(url, $scope.myObject)`, modifications to the object's properties in a transformRequest
557+
* function will be reflected on the scope and in any templates where the object is data-bound.
558+
* To prevent his, transform functions should have no side-effects.
559+
* If you need to modify properties, it is recommended to make a copy of the data, 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)