Is it possible to store the result of a promise in a variable within the constructor using Typescript?
I'm working with AdonisJS to retrieve data from the database, but the process involves using promises. How do I assign the result to a variable?
The variable needs to be accessible within 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)
}
Even though the console displays the values, the variables `teste1` and `teste2` remain undefined. Any assistance on resolving this issue would be greatly appreciated. Thank you for your help in advance.