How can I pass an array of values ​​of the same request parameter to a router?

As you can see from this bug fix , you can define multiple query parameters with the same name in the URL and make them serialized as 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 opposite is not true:

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

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

      

becomes:

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

      

When I want it to create:

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

      

Is there a way to do this?

If your answer is to parse a comma-separated value, why does the router create this function in one direction and not the other?

Edit:

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

+3


source to share


1 answer


Looks like this feature is fixed in Angular 4, see https://github.com/angular/angular/pull/15129



+1


source







All Articles