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
  • 3,405
  • 8
  • 30
  • 66

2 Answers2

2

Try this,

<a [routerLink]="['/experts']" [queryParams]="{ profession: 'handyman'}" class="category">
Sajeetharan
  • 203,447
  • 57
  • 330
  • 376
-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,471
  • 17
  • 87
  • 173
Anuradha Gunasekara
  • 5,837
  • 2
  • 23
  • 35