MCPcopy Index your code
hub / github.com/angular-ui/ui-router / $HttpParamSerializerJQLikeProvider

Function $HttpParamSerializerJQLikeProvider

test/angular/1.5/angular.js:10797–10868  ·  view source on GitHub ↗

@this

()

Source from the content-addressed store, hash-verified

10795
10796/** @this */
10797function $HttpParamSerializerJQLikeProvider() {
10798 /**
10799 * @ngdoc service
10800 * @name $httpParamSerializerJQLike
10801 *
10802 * @description
10803 *
10804 * Alternative {@link $http `$http`} params serializer that follows
10805 * jQuery's [`param()`](http://api.jquery.com/jquery.param/) method logic.
10806 * The serializer will also sort the params alphabetically.
10807 *
10808 * To use it for serializing `$http` request parameters, set it as the `paramSerializer` property:
10809 *
10810 * ```js
10811 * $http({
10812 * url: myUrl,
10813 * method: 'GET',
10814 * params: myParams,
10815 * paramSerializer: '$httpParamSerializerJQLike'
10816 * });
10817 * ```
10818 *
10819 * It is also possible to set it as the default `paramSerializer` in the
10820 * {@link $httpProvider#defaults `$httpProvider`}.
10821 *
10822 * Additionally, you can inject the serializer and use it explicitly, for example to serialize
10823 * form data for submission:
10824 *
10825 * ```js
10826 * .controller(function($http, $httpParamSerializerJQLike) {
10827 * //...
10828 *
10829 * $http({
10830 * url: myUrl,
10831 * method: 'POST',
10832 * data: $httpParamSerializerJQLike(myData),
10833 * headers: {
10834 * 'Content-Type': 'application/x-www-form-urlencoded'
10835 * }
10836 * });
10837 *
10838 * });
10839 * ```
10840 *
10841 * */
10842 this.$get = function() {
10843 return function jQueryLikeParamSerializer(params) {
10844 if (!params) return '';
10845 var parts = [];
10846 serialize(params, '', true);
10847 return parts.join('&');
10848
10849 function serialize(toSerialize, prefix, topLevel) {
10850 if (toSerialize === null || isUndefined(toSerialize)) return;
10851 if (isArray(toSerialize)) {
10852 forEach(toSerialize, function(value, index) {
10853 serialize(value, prefix + '[' + (isObject(value) ? index : '') + ']');
10854 });

Callers

nothing calls this directly

Calls 1

serializeFunction · 0.70

Tested by

no test coverage detected