@this
()
| 11997 | |
| 11998 | /** @this */ |
| 11999 | function $HttpParamSerializerJQLikeProvider() { |
| 12000 | /** |
| 12001 | * @ngdoc service |
| 12002 | * @name $httpParamSerializerJQLike |
| 12003 | * |
| 12004 | * @description |
| 12005 | * |
| 12006 | * Alternative {@link $http `$http`} params serializer that follows |
| 12007 | * jQuery's [`param()`](http://api.jquery.com/jquery.param/) method logic. |
| 12008 | * The serializer will also sort the params alphabetically. |
| 12009 | * |
| 12010 | * To use it for serializing `$http` request parameters, set it as the `paramSerializer` property: |
| 12011 | * |
| 12012 | * ```js |
| 12013 | * $http({ |
| 12014 | * url: myUrl, |
| 12015 | * method: 'GET', |
| 12016 | * params: myParams, |
| 12017 | * paramSerializer: '$httpParamSerializerJQLike' |
| 12018 | * }); |
| 12019 | * ``` |
| 12020 | * |
| 12021 | * It is also possible to set it as the default `paramSerializer` in the |
| 12022 | * {@link $httpProvider#defaults `$httpProvider`}. |
| 12023 | * |
| 12024 | * Additionally, you can inject the serializer and use it explicitly, for example to serialize |
| 12025 | * form data for submission: |
| 12026 | * |
| 12027 | * ```js |
| 12028 | * .controller(function($http, $httpParamSerializerJQLike) { |
| 12029 | * //... |
| 12030 | * |
| 12031 | * $http({ |
| 12032 | * url: myUrl, |
| 12033 | * method: 'POST', |
| 12034 | * data: $httpParamSerializerJQLike(myData), |
| 12035 | * headers: { |
| 12036 | * 'Content-Type': 'application/x-www-form-urlencoded' |
| 12037 | * } |
| 12038 | * }); |
| 12039 | * |
| 12040 | * }); |
| 12041 | * ``` |
| 12042 | * |
| 12043 | */ |
| 12044 | this.$get = function() { |
| 12045 | return function jQueryLikeParamSerializer(params) { |
| 12046 | if (!params) return ''; |
| 12047 | var parts = []; |
| 12048 | serialize(params, '', true); |
| 12049 | return parts.join('&'); |
| 12050 | |
| 12051 | function serialize(toSerialize, prefix, topLevel) { |
| 12052 | if (isArray(toSerialize)) { |
| 12053 | forEach(toSerialize, function(value, index) { |
| 12054 | serialize(value, prefix + '[' + (isObject(value) ? index : '') + ']'); |
| 12055 | }); |
| 12056 | } else if (isObject(toSerialize) && !isDate(toSerialize)) { |
nothing calls this directly
no test coverage detected