0

I have the following Html component:

<a [routerLink]="['experts']" [queryParams]="{profession:handyman}" class="category">
            <img src="../../assets/metal-saw.svg" width="60" height="60">
            <span>HandyMan</span>
        </a>

The problem is that when I click on the link, the experts route takes me, but without the queryparams. That is, queryparams does not seem to work but routerLink if it does. I am using angular in its version 5. Does anyone know why this happens?

AlejoDev
  • 4,345
  • 9
  • 36
  • 67

2 Answers2

2

Try this,

<a [routerLink]="['/experts']" [queryParams]="{ profession: 'handyman'}" class="category">
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
-1

Try this:

import {Router,NavigationExtras} from '@angular/router';

 //

constructor(private router: Router) {}

public navigate(): void {
      let navigationExtras: NavigationExtras = {
          queryParams: {'profession':handyman}
    };

    this.router.navigate(['/experts'], navigationExtras);
}

And in your HTML:

<a (click)="navigate()" class="category">
            <img src="../../assets/metal-saw.svg" width="60" height="60">
            <span>HandyMan</span>
        </a>

And go through this answer for more details. And follow the official doc for Angular routing.

halfer
  • 19,824
  • 17
  • 99
  • 186
Anuradha Gunasekara
  • 6,553
  • 2
  • 27
  • 37