![]() |
VOOZH | about |
The task is to pass query parameters with a routerLink, for that we can use the property binding concept to reach the goal. Using property binding, we can bind queryParams property and can provide the required details in the object.
What is Property Binding?
It is a concept where we use square bracket notation to bind data to Document Object Model(DOM) properties of Hypertext markup language(HTML) elements.
Syntax:
<a [routerLink]="[/path]" [queryParams]="{property:value}">
State Details
</a>
An Example of property binding:
Output:
Approach:
Below is the implementation of the above steps:
app.module.ts:
app.component.html:
After clicking on the anchor tag the URL will be displayed in the following way:
👁 ImageWe can also access the query parameters using the activated route.
In this way, we can pass query parameters via routerLink.
Fetching of query parameters:
state.component.ts :
state.component.html:
Output: