0

I need to set the [queryParams] for a routerLink by means of a component property, that is

@Component({
   ...
   template: '<a [routerLink]="..." [queryParams]="queryParams | async">...</a>
   ...
})
export class MyComponent {
   ...
   queryParams: any;
   ...
   constructor(route: ActivatedRoute) {
      this.queryParams = route.queryParams;
      ...
   }
}

But that approach doesn't work, there are no query params appended to the route. What am I missing?

Thorsten Westheider
  • 10,572
  • 14
  • 55
  • 97

1 Answers1

-1

You can append query paramerts youing this correct syntax

  this.router.navigate([yourRouteName], {queryParams:{ida:1,Idb:2,Idc:3}});

or

<a [routeLink]="yourRouteName, {queryParams:{ida:1,Idb:2,Idc:3}}"

then you can receive query parameter using the bellow syntax

import { Router, Route, ActivatedRoute } from '@angular/router';    
ngOnint{
        this.IDA= this.router.routerState.snapshot.root.queryParams["Ida"];
        this.IDB= this.router.routerState.snapshot.root.queryParams["Idb"];
        this.IDC= this.router.routerState.snapshot.root.queryParams["Idc"];
    }

Hope this will help you.

Aswin KV
  • 1,710
  • 2
  • 12
  • 23