'Access value in Subscribe's completed
I am subscribing an Observable as follows:
this.service.post(request).subscribe(
(value: Response> => {
// Do something with value
},
(error) => {
this.state = State.Invalid;
// Show errors on page
},
() => {
this.state = State.Completed;
// Redirect to new page:
this.router.navigate(['done'], { state: { v: value } });
}
);
Basically I am posting a request to an API and then I need to:
- Do something with the returned value;
- Show errors when an error exist
- Redirect to new page when returned value is processed.
How to access value in completed? This is why I need to access it:
this.router.navigate(['done'], { state: { v: value } });
Should I move this line to the next function?
(value: Response> => {
// Do something with value
// Redirect here
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
