Angular 2: How to provide interpolation using [routerLink]

I have the routing defined in the routing.ts file this way.

const routesapp: Routes= [ {path:'user/id', component:UserComponent} ]; export const:routing ModuleWithProviders = RouterModule.forRoot(routesapp, {useHash:true}); 

and in HTML

 <li class ="Some class"> <a href= "#/user/{{id}}"> Link </a> </li> 

How do I convert this to work with [routerLink]? From previous posts, I learned that we cannot add interpolation using [routerLink], that is, [routerLink] = ['user / {{id}}']

I want to add interpolation only in HTML, and I cannot add it to the routing file. Also, how to override useHash routing file in HTML?

+8
source share
2 answers

try it

 <li class ="Some class"> <a [routerLink]="['user', idVariable]">Link </a> </li> 
+16
source

This router link worked for me [routerLink] = "['/ edit', element.ID]"

I used it in the following: {{element.RequesterName}}

Thanks!

0
source

Source: https://habr.com/ru/post/1014784/


All Articles