Reputation: 76
I am not being able to see the queryparams in my url after clicking the desired buttons
here is my code
html file
<div class="row justify-content-center">
<div class="col-md-5 ">
<div class="list-group">
<a class="list-group-item " [routerLink]="['/product']"
[queryParams]="{category:Bread}"
>Bread</a>
<a class="list-group-item " [routerLink]="['/product']"
[queryParams]="{category:Dairy}"
>Dairy</a>
<a class="list-group-item " [routerLink]="['/product']"
[queryParams]="{category:Fruits}"
>Fruits</a>
<a class="list-group-item " [routerLink]="['/product']"
[queryParams]="{category:SeasoningsandSpices}"
>Seasonings and Spices</a>
<a class="list-group-item " [routerLink]="['/product']"
[queryParams]="{category:Vegetbales}"
>Vegetables</a>
</div>
</div>
</div>
i am only redirected to the page that has the routing link of '/product' but not seeing queryparams on the url and also how do i retrieve it if have queryparams ? here is the ss
Upvotes: 0
Views: 61
Reputation: 86740
but not seeing queryparams on the url
You are passing value of queryParam
as static value so you need to wrap it within quotes like this -
<a class="list-group-item " [routerLink]="['/product']"
[queryParams]="{category:'Bread'}"
>Bread</a>
how do i retrieve it if have queryparams
And to get query Params in the component use code like this in the constructor -
constructor(private route: ActivatedRoute){
this.route.queryParams.subscribe(params => {
// get params here with key name
});
}
Upvotes: 1
Reputation: 1382
Use ActivatedRoute
to get params from URL
private route: ActivatedRoute
this.route.queryParams.subscribe(params => {
// get params
});
Upvotes: 0