Angular中带有routerLink链接的动态queryParams

时间:2017-10-04 21:40:46

标签: angular angular-router routerlink queryparam

我正在尝试在循环中将参数传递给我的routerLink。以下是对象数组的样子: enter image description here

以下是routerLink链接的循环:

<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>

所需的输出:<a href="page?position=hello"></a>

0 个答案:

没有答案