-
Notifications
You must be signed in to change notification settings - Fork 27.5k
fix(ngResource): Add suport for nested params #1640
fix(ngResource): Add suport for nested params #1640
Conversation
Allow ngResource to properly construct a query string for params which have objects or arrays as values.
Just ran into this today and agree it would be great if it worked like jQuery.param method. I am hitting a Rails service and just trying to pass a simple array as a parameter. Note: This PR currently will encode arrays w/ index; e.g. parity with jQuery would be (by supplying index - Rails parses the parameter into a hash using the index as a key rather than an array). Parity w/ jQuery would exclude the index for array. |
following up - here's the issue related to $http where added ability to encode arrays that Igor referenced: I agree keeping it consistent would be best. Actually, has me wondering - why even have this encoding logic in angular-resource's Route.url() ... perhaps a better approach would be Route.url only deals with urlParams and pass along any remaining params on to $http to keep it DRY. |
@IgorMinar I was working on a PR to have resource delegate encoding of params to $http. The code is pretty straight forward and I think is a good change to DRY things up. However, I have one failing test related to this spec: 'should not encode @ in url params' with this comment: With the encoding of the params handled by http, this test fails which has me wondering why the fix for over aggressive encoding isn't in $http to begin with. |
It is a much needed (critical, i would say) feature, array serialization to x[]=one&x[]=two. Also, not sure if related, it is now impossible to set your path to something like "?q=text&x[]=one&x[]=two" at all. It gets changed to "?q=text&x[]=two". Could not yet find the responsible piece of code, though. Happens if $location is injected. |
Since there are different back-ends and encoding schemas maybe the way to move forward would be to add a configurable strategy (on the |
Being brought up by php/rails/jquery i always assumed that "?x[]=one&x[]=two" was the only desired serialization approach. And now i'm very confused to find out that there are other approaches, entirely blocking me from using angularjs with rails backend :( I had tremendous fun learning the framework up until this point though. I've looked into $httpProvider code briefly, but couldn't quite figure how to approach the 'configurable strategy' solution. May i ask for some tips on where to look? Also, how does $location link into this behavior? I guess i could work around this problem if i could keep $location from mangling the incoming query string. Would a separate issue for this be more helpful, since i'm not committing any code yet? |
I'll give it a try, thanks! |
Andrei, it should serialize as you expect. (I'm also using rails). |
Thank you so much for your fix, Mark. It does indeed work as expected. |
It appears that this functionality has been merged now. Can we close this PR then? @Phantoms - you mention another issue? If this is still the case, can you create a new issue/PR for it? |
Allow ngResource to properly construct a query string for params which
have objects or arrays as values.