Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly model querystring input which can contain multiple values #9477

Closed
2 tasks done
robwormald opened this issue Jun 22, 2016 · 4 comments
Closed
2 tasks done

Properly model querystring input which can contain multiple values #9477

robwormald opened this issue Jun 22, 2016 · 4 comments
Labels
area: router feature Issue that requests a new feature

Comments

@robwormald
Copy link
Contributor

From @xealot on June 10, 2016 16:3

Note: This is a copy of my issue from, #9138.

I don't know which is the appropriate location.

I'm submitting a ...

  • bug report
  • feature request

Current behavior

In the old router, the new router and the very new router querystring parameters always are accessible as {[k:string]:string}. To pass an array of values via the querystring we have to rely on encoding within the application to serialize and then deserialize the array. We should be able to simply rely on existing URL standard behavior.

Adding to my frustration, there is already a class, URLSearchParams that fully models the querystring but seems unused when retrieving url search params from the router.
https://angular.io/docs/ts/latest/api/http/URLSearchParams-class.html

Expected/desired behavior

When retrieving data parsed from a querystring it should be presented either in a datastructure that supports the standard or in a class that models it properly.

const q: Observable<URLSearchParams> = r.routerState.queryParams;
const q: Observable<{[k:string]:string[]}> = r.routerState.queryParams;

My vote is for the URLSearchParams version of course.

Copied from original issue: angular/vladivostok#35

@vsavkin vsavkin added the feature Issue that requests a new feature label Jun 29, 2016
@karel1980
Copy link

Related to #11374?

My suggestion would be to model the query params as {[k:string]: string | string[]}
Then you can do
var params = new URLSearchParams()
params.set('foo': 'bar');
and
params.set('foo': ['bar','qux']);

background material:
The RFC for URI - https://tools.ietf.org/html/rfc3986#section-3.4 certainly does not say that query parameters cannot be repeated. There is sentence which says that query parameters are 'often' key/value pairs, but there definitely no restriction on the number of times a parameter can be specified.

Coming from a Java background - JAX-RS (jsr 311) lets you specify a query parameter of type List or of List if you implement methods for converting from String to T.
https://jsr311.java.net/nonav/releases/1.1/javax/ws/rs/QueryParam.html
(as opposed to rails, php & co which seem inclined to use the foo[]=bar syntax)

@karel1980
Copy link

Maybe relevant: there is an 'append' method on URLSearchParams

@vsavkin
Copy link
Contributor

vsavkin commented Oct 10, 2016

Dup of #11374

@vsavkin vsavkin closed this as completed Oct 10, 2016
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: router feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests

3 participants