I\'m trying to extract the values from an observable, my subscription (component) code is as followed:
this.checkoutService.getDisabledDate().subscribe
(date
It's unclear from your question where "outside" is, but if it's after the call where you get the Observable then this is expected behavior
someMethod() {
this.checkoutService.getDisabledDate()
.subscribe(
// anything here is executed sometimes later when the response from the server arrives
dates=>{
this.formattedDate=dates;
// code that depends on the result goes here
},
(error:any)=>{console.log(error)}
);
// this is executed first
}
You can't get the value outside of subscribe. You can use map and return the result for the caller to subscribe, like done in getDisabledDate or you move the code to one of the callbacks.