Skip to content

Instantly share code, notes, and snippets.

@JonathanGawrych
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save JonathanGawrych/05739feab2bb1c9117bb to your computer and use it in GitHub Desktop.

Select an option

Save JonathanGawrych/05739feab2bb1c9117bb to your computer and use it in GitHub Desktop.
transformRequest to make requests made with angular transform Date objects into the long time, rather than iso string
// untested. Probably works. based off of angular's toJsonReplacer
transformRequest: [function(d) {
// why is angular.isFile or angular.isBlob not exposed? Who knows! Code copied here
if (!angular.isObject(d) ||
Object.prototype.toString.call(d) === '[object File]' ||
Object.prototype.toString.call(d) === '[object Blob]') {
return d;
}
return JSON.stringify(d, function(key, value) {
if (typeof key === 'string' && key.charAt(0) === '$') {
return undefined;
} else if (angular.isWindow(value)) {
return '$WINDOW';
} else if (value && document === value) {
return '$DOCUMENT';
} else if (angular.isScope(value)) {
return '$SCOPE';
} else if (angular.isDate(value)) {
return value.getTime();
}
return val;
});
}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment