Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
Why I got empty object on Angular route?

Why I got empty object from ActivatedRoute params and how to fix that?

  routeId$ = this.route.params.pipe(
    tap((params) => console.log(params)), // <--- {}
    pluck('id')
  );

I defined the :id in the route of the children:

    RouterModule.forChild([
      {
        path: '',
        component: OrdersComponent,
        children: [{ path: ':id', component: OrderComponent }], <-- here.
      },
    ]),

Because I want to use facade, I declared it in the providers to have facade instance for the component:

...
providers: [FooFacade],
})
export class OrderComponent {
  constructor(private facade: FooFacade) {}
  doWork() {
    console.log('doWork');
    this.facade.doWork();
  }

FooFacade is using the service.

I try to find why I got an empty object and not the id so I found out that works:

 routeIdWorks$ = this.route.firstChild.firstChild.firstChild.params.pipe(
    tap((params) => console.log(params)),
    pluck('id')
  );

But it's not the ideal solution because I have to specify alot of firstChild. also a function that aggrigate firstChild feel worng.

So there is a way to make this to work?

  routeId$ = this.route.params.pipe(
    tap((params) => console.log(params)),
    pluck('id')
  );

I also defined those options in the router root:

  {
        paramsInheritanceStrategy: 'always', <---??
        initialNavigation: 'enabledBlocking',
        enableTracing: false,
      }

stackblitz

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda