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

357
Visualizações
Can not get Data from resolver in angular

my resolve:

my resolve

my component:

my component

I haved tried "this.route.data.subscribe" and "this.route.snapshot.data['objectPost']" but i still can get the post's data. Can someone explain whhat is my problem please...? Thanks :D

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Try accessing through 'paramMap'

@Injectable({ providedIn: 'root' })
export class DemoResolver implements Resolve<any> {
  constructor() {}

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any>|Promise<any>|any {
    console.log(route.paramMap.get('postID')); // try with this code
  }
}

Note: Check if you have registered your resolver in your module as this example:

{
  provide: 'DemoResolver',
  useValue: (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => response
}

For more information: https://angular.io/api/router/Resolve

over 4 years ago · Santiago Trujillo Relatório

0

First thing you have to know about resolving is that route will change when resolved data is ready.

So, this is the flow:

  1. your route -> localhost:4200/child2.
  2. resolver takes the action.
  3. your route will change to localhost:4200/child2/:postID.

So when your resolver takes the action the route still is localhost:4200/child2 and route.params.postID will return undefined.

You can use Location from @angular/common to replaceState of url and then navigate to child2/:postID. This way you will have id in resolver.

over 4 years ago · Santiago Trujillo Relatório
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