How to access the returned data from getData() in printData? Can I store the data in a global variable?
The following is what I have as an example:
home.js
export class Home {
//d;
constructor() {
this.printData();
}
getData() {
httpClient.fetch('example.com/api/v')
.then(response => response.json())
.then(data => {
return data;
//this d = data;
});
}
printData() {
var data = this.getData();
console.log(data.name);
//console.log(this.d.name);
}
}