Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically create query Params in Angular 2

i want to achieve that the queryParams can be dynmamically passed it. For now i can set the values of the params dynamically, but not the keys

Here is my Code

onItemClick(item: FilterItem, group: FilterGroup, i: number) {

    let navigationExtras: NavigationExtras = {
      queryParams: { name : group.items[i].param }
    };
     this.router.navigate(['/search'], navigationExtras);
  }

I cannot put instead of "name" my group.name which is a string. I tried this:

 queryParams: { group.name: group.items[i].param }

But here i get syntax error. How can i put the "key" of a queryParam through an object like that?

like image 242
Emre Öztürk Avatar asked Mar 19 '17 17:03

Emre Öztürk


1 Answers

This should work:

 queryParams: { [group.name]: group.items[i].param }

See also Creating object with dynamic keys

like image 144
Günter Zöchbauer Avatar answered Sep 19 '22 21:09

Günter Zöchbauer