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

Function $HttpParamSerializerJQLikeProvider

test/angular/1.7/angular.js:11934–12008  ·  view source on GitHub ↗

@this

()

Source from the content-addressed store, hash-verified

11932
11933/** @this */
11934function $HttpParamSerializerJQLikeProvider() {
11935 /**
11936 * @ngdoc service
11937 * @name $httpParamSerializerJQLike
11938 *
11939 * @description
11940 *
11941 * Alternative {@link $http `$http`} params serializer that follows
11942 * jQuery's [`param()`](http://api.jquery.com/jquery.param/) method logic.
11943 * The serializer will also sort the params alphabetically.
11944 *
11945 * To use it for serializing `$http` request parameters, set it as the `paramSerializer` property:
11946 *
11947 * ```js
11948 * $http({
11949 * url: myUrl,
11950 * method: 'GET',
11951 * params: myParams,
11952 * paramSerializer: '$httpParamSerializerJQLike'
11953 * });
11954 * ```
11955 *
11956 * It is also possible to set it as the default `paramSerializer` in the
11957 * {@link $httpProvider#defaults `$httpProvider`}.
11958 *
11959 * Additionally, you can inject the serializer and use it explicitly, for example to serialize
11960 * form data for submission:
11961 *
11962 * ```js
11963 * .controller(function($http, $httpParamSerializerJQLike) {
11964 * //...
11965 *
11966 * $http({
11967 * url: myUrl,
11968 * method: 'POST',
11969 * data: $httpParamSerializerJQLike(myData),
11970 * headers: {
11971 * 'Content-Type': 'application/x-www-form-urlencoded'
11972 * }
11973 * });
11974 *
11975 * });
11976 * ```
11977 *
11978 */
11979 this.$get = function() {
11980 return function jQueryLikeParamSerializer(params) {
11981 if (!params) return '';
11982 var parts = [];
11983 serialize(params, '', true);
11984 return parts.join('&');
11985
11986 function serialize(toSerialize, prefix, topLevel) {
11987 if (isArray(toSerialize)) {
11988 forEach(toSerialize, function(value, index) {
11989 serialize(value, prefix + '[' + (isObject(value) ? index : '') + ']');
11990 });
11991 } else if (isObject(toSerialize) && !isDate(toSerialize)) {

Callers

nothing calls this directly

Calls 1

serializeFunction · 0.70

Tested by

no test coverage detected