-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Query params not serializes as expected #3740
Comments
This PR #3696 might fix this, will test it later |
+1 |
1 similar comment
+1 |
Please fix this. |
+1 |
3 similar comments
+1 |
+1 |
+1 |
This is silly. If you know you're dealing with a backend which understands that style of query, just append "[]" to the param name. There's nothing in any of the RFCs regarding URI construction or parsing which makes any statement about a special meaning of "[]". This feels like a wontfix, really. |
@caitp this one is coming back over and over again so at one point I was thinking of abstracting this requests params serialization (and probably parsing) part into a service and thus allow people to swap implementation to match their backend. This should be rather simple to do. Adding [] is definitively and option, just a bit of pain when you've got your object ready. |
@caitp I don't see how this is a silly request, serialization is a basic building block that many libraries build on top. Many time you are high in an abstraction that uses the Angular serialization underneath. So what you are proposing is not a viable option. Also appending [] only deals with array serialization. jQuery params also makes object serialization different, see above. Probably asking just to change this completly is an unreasonable request as people using Angular already have crafted their backend for the current way of doing things. But at least Angular should make it very easy to just swap strategies, so it uses that way across the board. |
Maybe the jQuery foundation should attend some IETF meetings and turn their quirk into an actual thing ;) I don't think it's a very good idea to do this just for the benefit of a handful of backends. What Angular is doing right now seems to be what is the expected behaviour. Now, someone comes up with a configurable way to do this which works well, then that's one thing, but I just don't see this as being a very good thing to force on people. |
+1 please fix.
But this is an ugly solution, which also depends on jQuery. |
+1 |
3 similar comments
+1 |
+1 |
+1 |
I think it should be possible to write a small library that adds a global interceptor to |
Thanks @ilyagelman! |
+1 |
+1 ASP.NET Web API recognizes either:
or
It would be very convenient if Angular supported this out of the box. |
Here's how I'm handling it right now: https://gist.github.com/gabrielmaldi/5453d87402db5a56c1a5 It seems very long because I included uri.js. But the key parts are queryStringParam.js (adapted from jQuery.param) and httpInterceptor.js. Maybe it helps someone. |
I really wish there was something that could be done for all the Rails/Grape developers who are used to dealing with $.params from jquery, but are trying to move to an angular-only front-end client. I think there enough people effected by this that it would make for a stellar option if we could configure our apps to turn on this style of serialization for GET requests. +1 |
@taelor I know this is a pain and we are going to provide an elegant solution for this in the near future. It is in the works. |
@pkozlowski-opensource thanks for the super quick reply, its very reassuring! |
+1 As long as the "elegant" solution doesn't come in the form of "2.X sorry we don't give a shit about 1.x", this would be fine. But... 1.5 years this is open, super annoying and still not fixed, no one assigned, so I would not hold my breath |
👍 |
A solution will be part of 1.4: http://angularjs.blogspot.fr/2014/12/planning-angular-14.html @danbarua @jchatel I'm afraid that those snarky comments are not helpful not appreciated... If you want to contribute please comment on the actual technical solution you would propose. |
Lets just implement jQuery param serializing, it will make people happy, I guess. We can even add a new "legacy" parameter to the http config to use jQuery's legacy serialization option, just to make the API less confusing for everyone. |
@caitp I'm on it. There is slightly more to it as we need to make sure that people can write tests easily. Going to share a gist with a proposed solution over the weekend. But yes, I'm working on it and it will be part of 1.4. |
I was just paraphrasing how 2.0 was announced, at least that's how I (and many others) took it. I think there was plenty of comments already mentioning the solution: jQuery param serialisation and +1 didn't have much effect in the last 1.5 year it seemed. |
For anyone interested in this issue here is the very first draft of a proposed solution for 1.4: https://gist.github.com/pkozlowski-opensource/5a57d28ccfeacaba7661 - if you care about it being solved properly please comment in the gist or in this issue directly. Unfortunately we can't simply implement jQuery's param logic by default as:
Very open to all the constructive comments, let's get it fixed as well as we can in 1.4. |
Closes angular#3740 Closes angular#7429 Closes angular#9224
Closes angular#3740 Closes angular#7429 Closes angular#9224
After reading through this long thread, I still didn't get a solution. Here is a simple one: module.run(['$http', '$httpParamSerializerJQLike', function($http, $httpParamSerializerJQLike) {
$http.defaults.paramSerializer = $httpParamSerializerJQLike;
}]); |
(Slightly) simpler (?) / shorter way of doing the same: module.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.paramSerializer = '$httpParamSerializerJQLike';
}]); |
Closes angular#3740 Closes angular#7429 Closes angular#9224 Closes angular#11461
@pkozlowski-opensource |
+1 |
Angular serializes query strings in a particular way that many backend frameworks (including Rails) don't understand. jQuery param on the other hand has been the standard for this for years.
Example 1
Angular serializes to
Jquery.param serializes to
Example 2
Angular serializes to:
jQuery.param serializes to
There are several closed issues related to this, but this seems to be a common problem, jquery.param looks likes the expected behaviour.
#1363
#3121
#1640
Some of the conversation on these issues seems to imply that this has been done, but I tested this using Angular 1.2 with the same results as before.
Please lets consider making Angular serialization equivalent to jQuery.param
Thanks
The text was updated successfully, but these errors were encountered: