Angular variable into routerLink
Asked Answered
O

3

21

I'm trying to pass an id in my routerLink, how could I concatenate it?

<a routerLink="['/details', {{data.id}}]"> </a> doesnt work.

Do you have solutions?

Thanks in advance

Ophiology answered 28/11, 2018 at 15:59 Comment(4)
I guess you have tried to put code inside post? It's not showing. Update it please.Skittle
Code please..and concatenate id with what? path?Potentiate
Sorry I forgot to put it between quotesOphiology
Remove the curly brackets ({{ }}) in what you have now. You just need data.id after the route name. That should work.Jenn
S
36

There you go.

<a [routerLink]="['/details', data.id]"> Link </a>
Skittle answered 28/11, 2018 at 16:13 Comment(1)
Technically this works but the recommended way is to pass it as the second argument. Please take a look at Aragom's answer.Megawatt
P
7

Parameters go as second item in the array syntax to router link, like this:

[routerLink]="['/details', data.id]

Read more here

Potentiate answered 28/11, 2018 at 16:15 Comment(0)
C
1

Similar to above, but you can also do this:

<a [routerLink]="['/details' + data.id]"> Link </a>
Cellulitis answered 11/11, 2021 at 19:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.