I am facing a situation with two modules, module.js and controller.js. In the module file, I have the following code:
export class Module {
constructor(){
const fetchParams = {
method: "GET",
mode: "cors",
cache: "default"
};
const url = 'https://swapi.co/api/people/';
fetch(url, fetchParams)
.then(res => {
if(!res.ok){
throw new Error(res.statusText);
}
return res.json();
})
.then(data => {
const characters = data.results;
this.characters = characters;
})
}
}
As for the controller file, it looks like this:
import {Module} from "./module";
class Controller extends Module{
constructor(){
super();
}
checkData(){
console.log(this.characters);
}
}
When running checkData(), I encounter an issue where the result is undefined. How can I ensure that I wait for the response from the module before accessing the data in checkData()? PS: I am utilizing webpack.