热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在Angular子组件中获取Route参数

如何解决《在Angular子组件中获取Route参数》经验,为你挑选了1个好方法。

我无法从Angular 6应用程序的子组件中获取路由参数

我在app-routing.module中设置了以下路由:

{
    path: 'item/:id',
    component: ItemLayoutComponent,
    children: [
        { path: '', redirectTo: 'inbox',  pathMatch: 'full' },
        { path: 'inbox', loadChildren: './feature/inbox/inbox.module#InboxModule' }
    ]
},

然后在我的inbox-routing-module.ts中:

{
    path: '',
    component: InboxComponent,
    children: [
        { path: '', redirectTo: 'messages',  pathMatch: 'full' },
        {
            path: 'messages', component: MessagesComponent
        },
    ]
}

这使我可以使用一个类似于以下网址的URL到达我的消息组件:

item/5200/inbox/messages

我的问题是,在我的ItemLayoutComponent中,我可以使用以下代码获取id字段的值(在本例中为5200):

this.route.snapshot.paramMap.get('id')

但是,我需要在MessagesComponent中使用此ID的值。目前,相同的代码使我为空。



1> Robbie Mills..:

原来我需要以下内容:

this.route.parent.parent.parent.snapshot.paramMap.get('id')

感谢@jonrsharpe为我指出正确的方向


推荐阅读
author-avatar
小编106
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有