how to assign the result of a promise in a variable inside the constructor in typescript?
I'm using adonisjs to collect the data from the database. But it uses a promise to collect the information from the database.
How can I put the result in a variable?
I need this variable to be in the constructor.
Below is the code.
private teste1: any
private teste2: any
constructor(protected ctx: HttpContextContract) {
Database.from('estoquepas').then(res => {
this.teste1 = res;
console.log(res)
})
Estoquepas.findBy('siagreId', this.IDSiagre.siagreId).then(res => {
this.teste2 = res;
console.log(res)
})
console.log(this.teste1)
console.log(this.teste2)
}
What is inside the consule is shown, however the variable teste1 and teste2 does not display and is undefined.
Can anyone help with this question, thank you in advance for your attention.