I've been working on processing data from an API using Angular 6. Despite seeing that the data is being returned in the Network tab, I'm having trouble processing it after the call is complete.
The data returned by my service:
{"profile": "German DJ and producer based in Berlin. He is the founder of a label."}
My fetch method:
public fetchData(): Observable<DiscogsRecord> {
return this.http.get(this.url).pipe(
map(response => response["profile"]),
catchError(this.errorHandler("Error loading music data.", []))
);
}
Defined interface for DiscogsRecord:
export interface DiscogsRecord {
profile: string;
}
Within ngOnInit:
ngOnInit() {
this.recs = [];
this.dataService.fetchData().subscribe(records => (this.recs = records));
console.log(this.recs);
... etc
Upon logging this.recs, it appears empty as an array: []. Can anyone spot what might be going wrong here?