When I instance a class1 in another class2, I couldn't retrieve the value of a class attribute which contains the result of the async method which is already called in the constructor of the first class (DbHelper).
Here is the sample
class1
export class DbHelper{
db: any;
constructor() {
this.createIndexDBStore();
}
//Init IndexDB store
async createIndexDBStore() {
this.db = await doSomething(...);
}
getDB() {
return this.db;
}
}
class2
export class test {
const dbHelper= new DbHelper();
const db = dbHelper.getDB(); // here the db is undefined
}
But when I return a string instead of the doSomething, the db variable will contain that string.