我想动态创建一个路由链接。
我已经加载了页面的html,但是,我需要在URL中使用一个id,这是稍后可用的。
HTML:
<a href="javascript:void(0)" routerLink="cartoonBoxUrl()" routerLinkActive="active">Add Content to Cartoon Box</a>此路由链接中的链接包含卡通盒的id (/carton-box/1)。此id在页面加载后可用。因此,我需要一种方法来创建一个路由链接,以包括此id。
所以我相信我们可以这样做:routerLink="'cartoon-box/' + id",但我希望将routerlink链接到一个组件函数
发布于 2016-11-11 22:00:55
<a href="javascript:void(0)" (click)=cartoonBoxUrl()>Add Content to Cartoon Box</a>在ts component.ts文件中执行以下操作
import {Router} from "@angular/router";
public ID: any;
constructor(private router: Router){}
cartoonBoxUrl(){
this.ID = Your LinkId;
this.router.navigate(['YourRouteLink/', this.ID]);
}https://stackoverflow.com/questions/40544937
复制相似问题