I have the following code that returns an observable, it checks if the this.data is valid JSON, otherwise it tries to fetch it from url. The fetching and everything works.
load():Observable<IStandardListOutput[]> {
return Observable.create(observer => {
if (this.needsFetch) {
var data;
this.http.get(this.data)
.map(res => {
var result = res.text();
// console.log(result);
try {
data = JSON.parse(result)
} catch (e) {
return Observable.of([{error:"ERROR LOADING JSON: " + this.data}]);
}
return data;
}).subscribe(res => {
observer.next(this._parse(res));
observer.complete();
});
}else {
observer.next(this._parse(this.data));
observer.complete();
}
});
}
Now in the map/subscribe portion of the observer I have the following:
let observable$ = this.loader.load(); // <-- load method above
observable$.map(res => {
console.warn ("IN MAP: " + JSON.stringify(res));
});
observable$.subscribe(res=> {
console.log("IN SUB: " + JSON.stringify(res));
},
err => {
console.log(JSON.stringify(err))
},
() => {
console.info("COMPLETE")
}
);
What I see in the output/console is only the "IN SUB" (subscribe) function and a "COMPLETE". The console.warn in the .map function is never executed.
Any help is highly appreciated, thanks in advance