Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 6 query param in the middle of a routerlink

How do you put a parameter into a routerlink.

I'm trying to do something like this:

<p *ngFor="let supplier of suppliers">
   <a [routerLink]="['/supplier/{{supplier.businessId}}/products']">
        View Products
   </a>
</p>
like image 796
Robbie Mills Avatar asked Aug 20 '18 06:08

Robbie Mills


1 Answers

You can access query params in routerlink like below.

 <a routerLink="/product/productDetails/{{item.product.id}}" title="Edit"> <span class="glyphicon glyphicon-pencil"></span> </a>

What is difference between routerLink and [routerLink] ?

As per your question in routerLink you can directly use queryparams as shown in above code but in [routerLink] you can set queryparams like this.

<a [routerLink]="['/user/bob']" [queryParams]="{debug: true}" fragment="education">
  link to user component
</a>

For more information visit this link : https://angular.io/api/router/RouterLink

like image 58
Aarsh Avatar answered Sep 27 '22 21:09

Aarsh