Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

355
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!