3

I am using resolve with routing in one component but in resolve, one HTTP call is dependent on other Promise call.

resolve(){
  return this.storage.getUser().then( user => {
    this.getVendorDetails(user.login);
  });
}

getVendorDetails(loginId) {
  return this.http.get('http://localhost:8080/user/getVendor/' + loginId);
}

In component when I am trying to get the data from ActivatedRoute

ngOnInit() {
  this.activatedRoute.data.subscribe( data => {
    console.log(data);
  });
}

I am getting undefined. Maybe I'm missing something in the resolve function. How can I get the getVendorDetails() response into ngOnInit() using ActivatedRoute.

1 Answer 1

4

Either make one an observabe, or the other one a promise and always return this:

resolve() {
  return this.storage.getUser().then(user => this.getVendorDetails(user.login).toPromise());
}

or

resolve() {
  return from(this.storage.getUser()).pipe(
    switchMap((user) => this.getVendorDetails(user.login))
  );
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.