I am facing an issue with passing the result of a GET request from Observable to Observer. The problem lies in the fact that the value becomes undefined because it communicates with the observer before the GET execution finishes.
observer:Observer<any> = {
next: objectFromObservable => { SomeActionWith() }
}
let outputToObserver;
this.http.get(myUrl).map((programs)=>{
const mapped = programs.json() as Program[];
outputToObserver=mapped //here we always have desired object
return mapped;
})
.subscribe(
(res)=>{
return res; //here we always have desired object
}
)
//Here outputToObserver is undefined, so above lines are executed before mapping
let observable:Observable<any> = Observable.create(function (obserwator) {
observer.next(outputToObserver)