Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

354
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda