I'm trying to get data from an API with a service. And then log it from inside a module which is later going to show it in a list. The variable shows up in the console.log in the service but not when I try to log it in de module
This same set up i've made before with ionic, I figured angular would work the same but that isn't the case here. I've already expanded the .subscribe function with error handling but no errors show up. I just don't know where to look.
api.service.ts
getPlacesData(): any {
let result = this.http.get(`${this.apiUrl}/places`, this.httpOptions).pipe(
map(response => {
console.log(response['data']);
response['data'];
})
);
return result;
}
}
test-dashboard.component.ts
constructor(private breakpointObserver: BreakpointObserver, private apiService: ApiService) {}
getPlacesData() {
this.apiService.getPlacesData().subscribe(
(placesData: Observable<any>) => {
console.log(placesData);
this.placesData = placesData;
console.log(this.placesData);
},
(error: string) => {
console.log('Received an errror: ' + error);
}
);
}
ngOnInit() {
this.getPlacesData();
}
}
I expect the second and third console.log to have the same output as the first one, but the output from those is "undefined" instead of:
(15) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]