jcroll
jcroll

Reputation: 7155

How to pass an array of values of same query parameter to the router?

As seen in this bug fix it is possible to define multiple query parameters of the same name in a url and have them serialized to an array:

http://localhost:4200?status=Deleted&status=Audio Issue

becomes:

  ngOnInit() {
    this.activatedRoute.queryParams.subscribe((params: Params) => {
      if (!params) {
        return;
      }
      console.log(params); // see below
    // {
    //   'status': [
    //     'Deleted',
    //     'Audio Issue'
    //   ],
    // }

However from my testing the reverse isn't true:

let queryParams = {
  'status': [
    'Deleted', 
    'Audio Issue',      
  ],
}

this.router.navigate([], { queryParams });

becomes:

http://localhost:4200?status=Deleted,Audio Issue

When I'd like it to produce:

http://localhost:4200?status=Deleted&status=Audio Issue

Is there any way to do this?

If your answer is to parse the comma delimited value, why have the router produce this functionality in one direction and not the other?

Edit:

Possibly fixed 6 days ago https://github.com/angular/angular/pull/15129

Upvotes: 4

Views: 6084

Answers (1)

jcroll
jcroll

Reputation: 7155

It appears this functionality is fixed in Angular 4 see https://github.com/angular/angular/pull/15129

Upvotes: 1

Related Questions