我的路线:
{
path: 'meldunki', canActivate: [Auth3Guard], component: MeldunekComponent, children: [
{path: ':id', component: MeldunekDetailComponent},
{path: ':id/edit', component: MeldunekEditComponent},
{path: '', pathMatch: 'full', component: MeldunekListComponent},
]
},
路线:meldunki / 21329 /编辑
当我从angular / router添加到Params的构造函数实例时:
constructor(
private params: Params) {
} angular抛出错误:无法解析MeldunekEditComponent的所有参数:(?)。
有人知道问题出在哪里吗?
答案 0 :(得分:1)
为了获取URL参数,您需要在构造函数中启动激活的路径模块。按原样使用
export class ABC {
id = this.route.snapshot.params.id;
constructor(
private route: ActivatedRoute) {}
}
答案 1 :(得分:1)
使用激活路线获取参数。在route.params上使用subscribe来监听param更改
import { ActivatedRoute } from '@angular/router';
constructor(private route: ActivatedRoute) {
const id = route.snapshot.params["id"];
console.log("param id",id);
//IF needed to subscribe
this.route.params.subscribe(
params => {
console.log(params['id'];);
});
}