我使用快照方法获取价值,但在这种情况下它在“类”之后获取价值 20 但我需要 33 路径,如获取
credits/33/classes/20 only 20 or credits/33/classes/ only null("")
Run Code Online (Sandbox Code Playgroud)
更新:我找到了我的问题的解决方案。
现在它正在正确获取 id。错误是访问了右子组件中的元素,在 Snapshot 版本中的子组件 MatDialog 组件中不起作用。
constructor(private route: ActivatedRoute) {}
ngOnInit(): void {
console.log(parseInt(this.route.snapshot.paramMap.get('id1')));
Run Code Online (Sandbox Code Playgroud)
如果您的 url 有 2 个 Id 值,则可以使用 route.parent 的快照
console.log(parseInt(this.route.parent.snapshot.paramMap.get('id1')));
}
Run Code Online (Sandbox Code Playgroud)