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

Function $HttpParamSerializerJQLikeProvider

lib/test/angular/1.4.3/angular.js:9168–9238  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9166}
9167
9168function $HttpParamSerializerJQLikeProvider() {
9169 /**
9170 * @ngdoc service
9171 * @name $httpParamSerializerJQLike
9172 * @description
9173 *
9174 * Alternative {@link $http `$http`} params serializer that follows
9175 * jQuery's [`param()`](http://api.jquery.com/jquery.param/) method logic.
9176 * The serializer will also sort the params alphabetically.
9177 *
9178 * To use it for serializing `$http` request parameters, set it as the `paramSerializer` property:
9179 *
9180 * ```js
9181 * $http({
9182 * url: myUrl,
9183 * method: 'GET',
9184 * params: myParams,
9185 * paramSerializer: '$httpParamSerializerJQLike'
9186 * });
9187 * ```
9188 *
9189 * It is also possible to set it as the default `paramSerializer` in the
9190 * {@link $httpProvider#defaults `$httpProvider`}.
9191 *
9192 * Additionally, you can inject the serializer and use it explicitly, for example to serialize
9193 * form data for submission:
9194 *
9195 * ```js
9196 * .controller(function($http, $httpParamSerializerJQLike) {
9197 * //...
9198 *
9199 * $http({
9200 * url: myUrl,
9201 * method: 'POST',
9202 * data: $httpParamSerializerJQLike(myData),
9203 * headers: {
9204 * 'Content-Type': 'application/x-www-form-urlencoded'
9205 * }
9206 * });
9207 *
9208 * });
9209 * ```
9210 *
9211 * */
9212 this.$get = function() {
9213 return function jQueryLikeParamSerializer(params) {
9214 if (!params) return '';
9215 var parts = [];
9216 serialize(params, '', true);
9217 return parts.join('&');
9218
9219 function serialize(toSerialize, prefix, topLevel) {
9220 if (toSerialize === null || isUndefined(toSerialize)) return;
9221 if (isArray(toSerialize)) {
9222 forEach(toSerialize, function(value) {
9223 serialize(value, prefix + '[]');
9224 });
9225 } else if (isObject(toSerialize) && !isDate(toSerialize)) {

Callers

nothing calls this directly

Calls 1

serializeFunction · 0.70

Tested by

no test coverage detected