问题
I'm trying to pass a parameter to my routerLink within a loop. Here is what the array of objects looks like:
Here is the loop with the routerLink link:
<li *ngFor="let Achievement of AllAchievements">
example from multiple sources
does not work with a variable 'x'. Outputs the letter x
<a routerLink="page" [queryParams]="{x : 1}">anchor text</a>
example from multiple sources
link is outputted /%5B'page',%20%7BAchievement.type%20:%20'hello'%7D%20%5D'
<a routerLink="['page', {Achievement.type : 'hello'} ]">anchor text</a>
outputs long/encoded string as param value
<a [routerLink]="['page']" queryParams="{ [Achievement.type] : 'hello' }">anchor text</a>
</li>
Desired output: <a href="page?position=hello"></a>
来源:https://stackoverflow.com/questions/46574652/dynamic-queryparams-with-a-routerlink-link-in-angular