本文介绍了角度2:如何通过[routerLink]提供插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我以这种方式在routing.ts文件中定义了路由.
I have routing defined in routing.ts file in this way.
const routesapp: Routes= [
{path:'user/id', component:UserComponent}
];
export const:routing ModuleWithProviders = RouterModule.forRoot(routesapp, {useHash:true});
和HTML
<li class ="Some class">
<a href= "#/user/{{id}}"> Link </a>
</li>
如何将其转换为可与[routerLink]一起使用?从以前的帖子中,我了解到我们无法使用[routerLink]添加插值,即[routerLink] = ['user/{{id}}']
How do I convert this to work with [routerLink]? From previous posts I learnt that we cannot add interpolation with [routerLink], i.e [routerLink] = ['user/{{id}}']
我只想在HTML中添加插值,而不能在路由文件中添加.另外,如何在HTML中覆盖路由文件的useHash?
I want to add interpolation in HTML only and I cannot add it in routing file. Also, How to override useHash of routing file in HTML?
推荐答案
尝试一下
<li class ="Some class">
<a [routerLink]="['user', idVariable]">Link </a>
</li>
这篇关于角度2:如何通过[routerLink]提供插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!