I am currently trying to update the current page by modifying or adding the query parameter "categoryId". When I attempt:
<a
[routerLink]=""
[queryParams]="{ categoryId: category!.id }"
queryParamsHandling="merge"
>
It works perfectly, but I would prefer to use a constant for the query parameter name to easily make changes in the future without searching through each occurrence.
Within the component.ts file, I have defined the property:
categoryIdQueryParamName = QueryParamNames.CATEGORY_ID;
I have attempted the following:
<a
[routerLink]=""
[queryParams]="{ {{'"' + categoryIdQueryParamName + '"' }}: category!.id }"
queryParamsHandling="merge"
>
After reviewing: , I also tried:
<a
[routerLink]=""
[queryParams]="{ [categoryIdQueryParamName]: category!.id }"
queryParamsHandling="merge"
>
However, I am still encountering a compilation error. If possible, can you provide guidance on the correct approach? Additionally, I am aware that I could achieve this programmatically using (click)
, but I prefer using <a [routerLink]>
to benefit from the ability to right-click and open links in new tabs.