I'm using ngOnInit in order to get a response from a Loopback API call. The property I initialize inside this scope can't be used outside the subscribe scope. I know this is a simple answer but I'm just not seeing it
private siteData: Kiosk;
constructor(private dataService: DataService){}
ngOnInit(){
this.dataService.getDataByID(this.dataService.getSiteID())
.subscribe((data:Site) => {
this.siteData = data;
console.log(this.siteData); // This outputs correctly
});
console.log(this.siteData); // This is undefined
}
site: any[] = [{
title: this.siteData.title, // this is undefined and throws error
}];
I expect output to not be undefined and be the data that is in the response