In the process of implementing the Spotify api into my Ionic 3 app, I encountered an issue where the data retrieved appears as undefined when attempting to log it. Let me share some code and delve deeper into the problem. Here is the function getData() that pulls the data:
getData(){
console.log("getData has been called!!!");
return this.http.get(this.dataUrl).map((res) => {
res.json(),
console.log(res.json())//this works fine
});
}
The above code functions without any disruptions. It resides within a service referred to as 'soundData'. However, the trouble arises with the subsequent snippet of code. Upon logging the data retrieved, it displays as undefined in the browser:
ionViewDidLoad(){
this.soundData.getData().subscribe(
returnedData=> {
this.data = returnedData;
console.log(this.data) //this shows as undefined
},
returnedError => {
this.error = returnedError;
});
}
I am puzzled as to what might be causing this issue. On the surface, everything seems to be functioning correctly, yet there could be something overlooked due to my limited experience with TypeScript and Ionic.