【发布时间】:2019-03-24 04:58:24
【问题描述】:
我有一条带有动态路径段的路线
const route:Routes=[
{path:'customers',component:CustomerComponent}
{path:'customers/:id',component:CustomerComponent}
]
所以在我的客户组件中,我使用 身份证号码;
constructor(private route:ActivatedRoute){}
ngOnInit(){
this.id= this.route.snapshot.params['id'];
console.log("Id is :",this.id)
}
当我从另一个组件转到此路由路径时控制台日志“Id 为:1”或第一次转到此路由时它正常工作“localhost:4200/customers/1”但问题发生了。我写了一个链接 customer.html 文件
<a [routerLink]="['/customer',2]">loadID2</a>
当单击此链接时,URL 更改为“localhost:4200/customers/2”,但控制台日志不起作用,它没有显示“Id is :2”,没有控制台日志。 我的问题为什么会发生这种情况?,网址已经更改,但 ngOninit 无法正常工作。你能帮我解决这个问题吗
【问题讨论】:
-
尝试使用 ParamMap angular.io/api/router/ParamMap
标签: angular