MCPcopy Create free account
hub / github.com/angular-ui/ui-grid / $HttpParamSerializerJQLikeProvider

Function $HttpParamSerializerJQLikeProvider

lib/test/angular/1.5.0/angular.js:10053–10123  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10051}
10052
10053function $HttpParamSerializerJQLikeProvider() {
10054 /**
10055 * @ngdoc service
10056 * @name $httpParamSerializerJQLike
10057 * @description
10058 *
10059 * Alternative {@link $http `$http`} params serializer that follows
10060 * jQuery's [`param()`](http://api.jquery.com/jquery.param/) method logic.
10061 * The serializer will also sort the params alphabetically.
10062 *
10063 * To use it for serializing `$http` request parameters, set it as the `paramSerializer` property:
10064 *
10065 * ```js
10066 * $http({
10067 * url: myUrl,
10068 * method: 'GET',
10069 * params: myParams,
10070 * paramSerializer: '$httpParamSerializerJQLike'
10071 * });
10072 * ```
10073 *
10074 * It is also possible to set it as the default `paramSerializer` in the
10075 * {@link $httpProvider#defaults `$httpProvider`}.
10076 *
10077 * Additionally, you can inject the serializer and use it explicitly, for example to serialize
10078 * form data for submission:
10079 *
10080 * ```js
10081 * .controller(function($http, $httpParamSerializerJQLike) {
10082 * //...
10083 *
10084 * $http({
10085 * url: myUrl,
10086 * method: 'POST',
10087 * data: $httpParamSerializerJQLike(myData),
10088 * headers: {
10089 * 'Content-Type': 'application/x-www-form-urlencoded'
10090 * }
10091 * });
10092 *
10093 * });
10094 * ```
10095 *
10096 * */
10097 this.$get = function() {
10098 return function jQueryLikeParamSerializer(params) {
10099 if (!params) return '';
10100 var parts = [];
10101 serialize(params, '', true);
10102 return parts.join('&');
10103
10104 function serialize(toSerialize, prefix, topLevel) {
10105 if (toSerialize === null || isUndefined(toSerialize)) return;
10106 if (isArray(toSerialize)) {
10107 forEach(toSerialize, function(value, index) {
10108 serialize(value, prefix + '[' + (isObject(value) ? index : '') + ']');
10109 });
10110 } else if (isObject(toSerialize) && !isDate(toSerialize)) {

Callers

nothing calls this directly

Calls 1

serializeFunction · 0.70

Tested by

no test coverage detected