@@ -23,13 +23,17 @@ function $HttpParamSerializerProvider() {
23
23
* @name $httpParamSerializer
24
24
* @description
25
25
*
26
- * Default $http params serializer that converts objects to a part of a request URL
26
+ * Default { @link $http `$http`} params serializer that converts objects to strings
27
27
* according to the following rules:
28
+ *
28
29
* * `{'foo': 'bar'}` results in `foo=bar`
29
30
* * `{'foo': Date.now()}` results in `foo=2015-04-01T09%3A50%3A49.262Z` (`toISOString()` and encoded representation of a Date object)
30
31
* * `{'foo': ['bar', 'baz']}` results in `foo=bar&foo=baz` (repeated key for each array element)
31
32
* * `{'foo': {'bar':'baz'}}` results in `foo=%7B%22bar%22%3A%22baz%22%7D"` (stringified and encoded representation of an object)
33
+ *
34
+ * Note that serializer will sort the request parameters alphabetically.
32
35
* */
36
+
33
37
this . $get = function ( ) {
34
38
return function ngParamSerializer ( params ) {
35
39
if ( ! params ) return '' ;
@@ -56,7 +60,42 @@ function $HttpParamSerializerJQLikeProvider() {
56
60
* @name $httpParamSerializerJQLike
57
61
* @description
58
62
*
59
- * Alternative $http params serializer that follows jQuery's [`param()`](http://api.jquery.com/jquery.param/) method logic.
63
+ * Alternative {@link $http `$http`} params serializer that follows
64
+ * jQuery's [`param()`](http://api.jquery.com/jquery.param/) method logic.
65
+ * The serializer will also sort the params alphabetically.
66
+ *
67
+ * To use it for serializing `$http` request parameters, set it as the `paramSerializer` property:
68
+ *
69
+ * ```js
70
+ * $http({
71
+ * url: myUrl,
72
+ * method: 'GET',
73
+ * params: myParams,
74
+ * paramSerializer: '$httpParamSerializerJQLike'
75
+ * });
76
+ * ```
77
+ *
78
+ * It is also possible to set it as the default `paramSerializer` in the {@link $httpProvider#defaults `$httpProvider`}.
79
+ *
80
+ * Additionally, you can inject the serializer and use it explicitly, for example to serialize data for form
81
+ * submission:
82
+ *
83
+ * ```js
84
+ * .controller(function($http, $httpParamSerializerJQLike) {
85
+ * //...
86
+ *
87
+ * $http({
88
+ * url: myUrl,
89
+ * method: 'POST',
90
+ * data: $httpParamSerializerJQLike(myData),
91
+ * headers: {
92
+ * 'Content-Type': 'application/x-www-form-urlencoded'
93
+ * }
94
+ * });
95
+ *
96
+ * });
97
+ * ```
98
+ *
60
99
* */
61
100
this . $get = function ( ) {
62
101
return function jQueryLikeParamSerializer ( params ) {
@@ -230,10 +269,11 @@ function $HttpProvider() {
230
269
* - **`defaults.headers.put`**
231
270
* - **`defaults.headers.patch`**
232
271
*
233
- * - **`defaults.paramSerializer`** - {string|function(Object<string,string>):string} - A function used to prepare string representation
234
- * of request parameters (specified as an object).
235
- * If specified as string, it is interpreted as a function registered with the {@link auto.$injector $injector}.
236
- * Defaults to {@link ng.$httpParamSerializer $httpParamSerializer}.
272
+ *
273
+ * - **`defaults.paramSerializer`** - `{string|function(Object<string,string>):string}` - A function
274
+ * used to the prepare string representation of request parameters (specified as an object).
275
+ * If specified as string, it is interpreted as a function registered with the {@link auto.$injector $injector}.
276
+ * Defaults to {@link ng.$httpParamSerializer $httpParamSerializer}.
237
277
*
238
278
**/
239
279
var defaults = this . defaults = {
@@ -708,9 +748,8 @@ function $HttpProvider() {
708
748
*
709
749
* - **method** – `{string}` – HTTP method (e.g. 'GET', 'POST', etc)
710
750
* - **url** – `{string}` – Absolute or relative URL of the resource that is being requested.
711
- * - **params** – `{Object.<string|Object>}` – Map of strings or objects which will be turned
712
- * to `?key1=value1&key2=value2` after the url. If the value is not a string, it will be
713
- * JSONified.
751
+ * - **params** – `{Object.<string|Object>}` – Map of strings or objects which will be serialized
752
+ * with the `paramSerializer` and appended as GET parameters.
714
753
* - **data** – `{string|Object}` – Data to be sent as the request message data.
715
754
* - **headers** – `{Object}` – Map of strings or functions which return strings representing
716
755
* HTTP headers to send to the server. If the return value of a function is null, the
@@ -728,10 +767,14 @@ function $HttpProvider() {
728
767
* transform function or an array of such functions. The transform function takes the http
729
768
* response body, headers and status and returns its transformed (typically deserialized) version.
730
769
* See {@link ng.$http#overriding-the-default-transformations-per-request
731
- * Overriding the Default Transformations}
732
- * - **paramSerializer** - {string|function(Object<string,string>):string} - A function used to prepare string representation
733
- * of request parameters (specified as an object).
734
- * Is specified as string, it is interpreted as function registered in with the {$injector}.
770
+ * Overriding the Default TransformationjqLiks}
771
+ * - **paramSerializer** - `{string|function(Object<string,string>):string}` - A function used to
772
+ * prepare the string representation of request parameters (specified as an object).
773
+ * If specified as string, it is interpreted as function registered with the
774
+ * {@link $injector $injector}, which means you can create your own serializer
775
+ * by registering it as a {@link auto.$provide#service service}.
776
+ * The default serializer is the {@link $httpParamSerializer $httpParamSerializer};
777
+ * alternatively, you can use the {@link $httpParamSerializerJQLike $httpParamSerializerJQLike}
735
778
* - **cache** – `{boolean|Cache}` – If true, a default $http cache will be used to cache the
736
779
* GET request, otherwise if a cache instance built with
737
780
* {@link ng.$cacheFactory $cacheFactory}, this cache will be used for
0 commit comments