@this
()
| 11293 | |
| 11294 | /** @this */ |
| 11295 | function $HttpParamSerializerJQLikeProvider() { |
| 11296 | /** |
| 11297 | * @ngdoc service |
| 11298 | * @name $httpParamSerializerJQLike |
| 11299 | * |
| 11300 | * @description |
| 11301 | * |
| 11302 | * Alternative {@link $http `$http`} params serializer that follows |
| 11303 | * jQuery's [`param()`](http://api.jquery.com/jquery.param/) method logic. |
| 11304 | * The serializer will also sort the params alphabetically. |
| 11305 | * |
| 11306 | * To use it for serializing `$http` request parameters, set it as the `paramSerializer` property: |
| 11307 | * |
| 11308 | * ```js |
| 11309 | * $http({ |
| 11310 | * url: myUrl, |
| 11311 | * method: 'GET', |
| 11312 | * params: myParams, |
| 11313 | * paramSerializer: '$httpParamSerializerJQLike' |
| 11314 | * }); |
| 11315 | * ``` |
| 11316 | * |
| 11317 | * It is also possible to set it as the default `paramSerializer` in the |
| 11318 | * {@link $httpProvider#defaults `$httpProvider`}. |
| 11319 | * |
| 11320 | * Additionally, you can inject the serializer and use it explicitly, for example to serialize |
| 11321 | * form data for submission: |
| 11322 | * |
| 11323 | * ```js |
| 11324 | * .controller(function($http, $httpParamSerializerJQLike) { |
| 11325 | * //... |
| 11326 | * |
| 11327 | * $http({ |
| 11328 | * url: myUrl, |
| 11329 | * method: 'POST', |
| 11330 | * data: $httpParamSerializerJQLike(myData), |
| 11331 | * headers: { |
| 11332 | * 'Content-Type': 'application/x-www-form-urlencoded' |
| 11333 | * } |
| 11334 | * }); |
| 11335 | * |
| 11336 | * }); |
| 11337 | * ``` |
| 11338 | * |
| 11339 | * */ |
| 11340 | this.$get = function() { |
| 11341 | return function jQueryLikeParamSerializer(params) { |
| 11342 | if (!params) return ''; |
| 11343 | var parts = []; |
| 11344 | serialize(params, '', true); |
| 11345 | return parts.join('&'); |
| 11346 | |
| 11347 | function serialize(toSerialize, prefix, topLevel) { |
| 11348 | if (toSerialize === null || isUndefined(toSerialize)) return; |
| 11349 | if (isArray(toSerialize)) { |
| 11350 | forEach(toSerialize, function(value, index) { |
| 11351 | serialize(value, prefix + '[' + (isObject(value) ? index : '') + ']'); |
| 11352 | }); |
nothing calls this directly
no test coverage detected