@@ -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,43 @@ 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
79
+ * {@link $httpProvider#defaults `$httpProvider`}.
80
+ *
81
+ * Additionally, you can inject the serializer and use it explicitly, for example to serialize
82
+ * form data for submission:
83
+ *
84
+ * ```js
85
+ * .controller(function($http, $httpParamSerializerJQLike) {
86
+ * //...
87
+ *
88
+ * $http({
89
+ * url: myUrl,
90
+ * method: 'POST',
91
+ * data: $httpParamSerializerJQLike(myData),
92
+ * headers: {
93
+ * 'Content-Type': 'application/x-www-form-urlencoded'
94
+ * }
95
+ * });
96
+ *
97
+ * });
98
+ * ```
99
+ *
60
100
* */
61
101
this . $get = function ( ) {
62
102
return function jQueryLikeParamSerializer ( params ) {
@@ -230,10 +270,11 @@ function $HttpProvider() {
230
270
* - **`defaults.headers.put`**
231
271
* - **`defaults.headers.patch`**
232
272
*
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}.
273
+ *
274
+ * - **`defaults.paramSerializer`** - `{string|function(Object<string,string>):string}` - A function
275
+ * used to the prepare string representation of request parameters (specified as an object).
276
+ * If specified as string, it is interpreted as a function registered with the {@link auto.$injector $injector}.
277
+ * Defaults to {@link ng.$httpParamSerializer $httpParamSerializer}.
237
278
*
238
279
**/
239
280
var defaults = this . defaults = {
@@ -708,9 +749,8 @@ function $HttpProvider() {
708
749
*
709
750
* - **method** – `{string}` – HTTP method (e.g. 'GET', 'POST', etc)
710
751
* - **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.
752
+ * - **params** – `{Object.<string|Object>}` – Map of strings or objects which will be serialized
753
+ * with the `paramSerializer` and appended as GET parameters.
714
754
* - **data** – `{string|Object}` – Data to be sent as the request message data.
715
755
* - **headers** – `{Object}` – Map of strings or functions which return strings representing
716
756
* HTTP headers to send to the server. If the return value of a function is null, the
@@ -728,10 +768,14 @@ function $HttpProvider() {
728
768
* transform function or an array of such functions. The transform function takes the http
729
769
* response body, headers and status and returns its transformed (typically deserialized) version.
730
770
* 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}.
771
+ * Overriding the Default TransformationjqLiks}
772
+ * - **paramSerializer** - `{string|function(Object<string,string>):string}` - A function used to
773
+ * prepare the string representation of request parameters (specified as an object).
774
+ * If specified as string, it is interpreted as function registered with the
775
+ * {@link $injector $injector}, which means you can create your own serializer
776
+ * by registering it as a {@link auto.$provide#service service}.
777
+ * The default serializer is the {@link $httpParamSerializer $httpParamSerializer};
778
+ * alternatively, you can use the {@link $httpParamSerializerJQLike $httpParamSerializerJQLike}
735
779
* - **cache** – `{boolean|Cache}` – If true, a default $http cache will be used to cache the
736
780
* GET request, otherwise if a cache instance built with
737
781
* {@link ng.$cacheFactory $cacheFactory}, this cache will be used for
0 commit comments