I have a function which returns an observable
getData(){
return this.http.get<{mat: any[], mat_auf: any[], mat_lok: any[], auf_an: any[]}>(this.authUrl + 'get/mat-data').pipe(
map(({mat, mat_auf, mat_lok, auf_an}) => {
console.log("AuthService", {mat, mat_auf, mat_lok, auf_an}); // correct data format
mat.map(mat => {
this.matAdapter.adapt(mat);
});
mat_auf.map(mat_auf => {
this.mat_aufAdapter.adapt(mat_auf);
});
mat_lok.map(lok => {
this.lokAdapter.adapt(lok)
});
auf_an.map(an => {
this.aufAdapter.adapt(an)
});
})
);
}
The conversion by the adapters works fine if I look in the console but when I try to subscribe to the Observable in another component I get undefined:
ngOnInit(){
this.authSrv.getData().subscribe(res => console.log(res)) // res is undefined but why?
}
An adapter looks like this:
@Injectable({
providedIn: "root"
})
export class MatAdapter implements Adapter<Mat>{
adapt(mat: any): Mat {
return new Mat(mat.ID, mat.name, mat.location);
}
}
As I said the adapters work fine as in the console the correct object is logged. But why is the data undefined, when I try to subscribe to the observable? I think I use the map function wrongly.
Any help is appreciated. If further information is needed, please leave a comment. Thank you