How to get :id param of child route from parent component in Angular2

Discussão em 'Angular' iniciado por Fernando Popoca Ortiz, Outubro 30, 2024.

  1. I'm trying to get the :id param defined in

    RouterModule.forRoot([
    {
    path: 'orders',
    component: ListComponent,
    children: [
    {
    path: 'view/:id',
    component: ViewComponent
    },
    ]
    }
    ])


    from ListComponent.

    I already tried:

    route: ActivatedRoute

    route.params.subscribe(params => {
    let id = +params['id'];
    })


    from ListComponent, but the params array is empty, I suppose it's because the :id param belongs to ViewComponent not ListComponent.

    How can I get the id param in ListComponent?

    Continue reading...

Compartilhe esta Página