@this
()
| 11363 | |
| 11364 | /** @this */ |
| 11365 | function $HttpParamSerializerJQLikeProvider() { |
| 11366 | /** |
| 11367 | * @ngdoc service |
| 11368 | * @name $httpParamSerializerJQLike |
| 11369 | * |
| 11370 | * @description |
| 11371 | * |
| 11372 | * Alternative {@link $http `$http`} params serializer that follows |
| 11373 | * jQuery's [`param()`](http://api.jquery.com/jquery.param/) method logic. |
| 11374 | * The serializer will also sort the params alphabetically. |
| 11375 | * |
| 11376 | * To use it for serializing `$http` request parameters, set it as the `paramSerializer` property: |
| 11377 | * |
| 11378 | * ```js |
| 11379 | * $http({ |
| 11380 | * url: myUrl, |
| 11381 | * method: 'GET', |
| 11382 | * params: myParams, |
| 11383 | * paramSerializer: '$httpParamSerializerJQLike' |
| 11384 | * }); |
| 11385 | * ``` |
| 11386 | * |
| 11387 | * It is also possible to set it as the default `paramSerializer` in the |
| 11388 | * {@link $httpProvider#defaults `$httpProvider`}. |
| 11389 | * |
| 11390 | * Additionally, you can inject the serializer and use it explicitly, for example to serialize |
| 11391 | * form data for submission: |
| 11392 | * |
| 11393 | * ```js |
| 11394 | * .controller(function($http, $httpParamSerializerJQLike) { |
| 11395 | * //... |
| 11396 | * |
| 11397 | * $http({ |
| 11398 | * url: myUrl, |
| 11399 | * method: 'POST', |
| 11400 | * data: $httpParamSerializerJQLike(myData), |
| 11401 | * headers: { |
| 11402 | * 'Content-Type': 'application/x-www-form-urlencoded' |
| 11403 | * } |
| 11404 | * }); |
| 11405 | * |
| 11406 | * }); |
| 11407 | * ``` |
| 11408 | * |
| 11409 | */ |
| 11410 | this.$get = function() { |
| 11411 | return function jQueryLikeParamSerializer(params) { |
| 11412 | if (!params) return ''; |
| 11413 | var parts = []; |
| 11414 | serialize(params, '', true); |
| 11415 | return parts.join('&'); |
| 11416 | |
| 11417 | function serialize(toSerialize, prefix, topLevel) { |
| 11418 | if (isArray(toSerialize)) { |
| 11419 | forEach(toSerialize, function(value, index) { |
| 11420 | serialize(value, prefix + '[' + (isObject(value) ? index : '') + ']'); |
| 11421 | }); |
| 11422 | } else if (isObject(toSerialize) && !isDate(toSerialize)) { |
nothing calls this directly
no test coverage detected