0

Angular's $http service can automatically convert an object into URL params. I.e. in following code params will be converted to date=2014-12-11T18:00:00.000Z&name=MyName

$http({
     method: "GET",
     url: url,
     params: {date: new Date(), name: 'MyName'}
})

Question: how I can manually convert my object into url parameters?

I found that I can do it using the $param method of JQuery, but the problem is that when using JQuery it converts dates in worng format: date=Fri+Dec+12+2014+00%3A00%3A00+GMT%2B0600+(Ekaterinburg+Standard+Time), but I want to send dates in Angular's format:

date=2014-12-11T18:00:00.000Z

In other words I need something like this:

var params = {date: new Date(), name: 'MyName'};
var paramsString = angular.toUrlParams(params); // should output `date=2014-12-11T18:00:00.000Z&name=MyName`
JAAulde
  • 19,250
  • 5
  • 52
  • 63
WelcomeTo
  • 19,843
  • 53
  • 170
  • 286

1 Answers1

0

Convert the dates into that string format before passing them to jQuery.

It doesn't do anything specific to the dates under-the-hood, this is simply the default way to cast a date object into a string as per the JS spec.

Incognito
  • 20,537
  • 15
  • 80
  • 120