angular - 角度嵌套路由父到子变量
问题描述
我有这条路线:
{
path: ':parent_id',
component: Parent,
children: [
{
path: 'child',
children: [
{
path: ':child_id',
component: Child
}
]
}
]
}
如何从子组件中检索 parent_id 值?
解决方案
您应该可以使用ActivatedRoute
首先导入它:import {ActivatedRoute} from "@angular/router";
然后尝试这样的事情:
constructor(private route: ActivatedRoute) {
this.route.parent.params.subscribe((params) => {
console.log(params); // This would show you all the available params
if (params['parent_id']) {
console.log(params['term']) // Prints the console parent_id param
}
});
}
推荐阅读
- python - 尽管进程已死,为什么我会收到子进程资源警告?
- python - Pandas 中的高级数据透视表
- ios - 如何将我的项目从使用 Storyboard 转变为不再使用 Storyboard?
- javascript - 限制安卓设备的字段输入
- vue.js - 在Vue router-link中使用Object作为参数的路径问题
- windows - 绑定地址失败 http://127.0.0.1:59074: 地址已在使用中
- domain-driven-design - 域模型中的 ID,以防自然 ID 不可用
- time-complexity - 将 P=2^(logN) 重写为 log2(P) = log2(N) 的解释是什么?
- php - 如何使用参数在特定页面上设置cookie
- swift - 两个AVPlayer,怎么知道哪一个玩完了