【发布时间】:2021-01-09 07:38:21
【问题描述】:
我需要将 id 作为参数传递给我的角度组件
在我的 html 中我有这样的东西
<a [routerLink]="['/viewjobdetail', currentJob.id]">
{{ currentJob.title }}
</a>
app.module.ts RouterModule.forRoot 配置为
{ path: 'viewjobdetail/:id', component: JobDetailComponent }
在我的调用组件中,我有
import { ActivatedRoute } from '@angular/router';
constructor(private route: ActivatedRoute){}
ngOnInit(): void {
this.route.queryParams.subscribe(params => {
debugger;
var a = params['id'];
this.displayJobId = parseInt(params['id']);
});
但是当我检查它时它总是显示 undefined for a,我在这里做错了什么? }
【问题讨论】:
标签: angular typescript url-routing angular2-routing