0
getListTodayOrders(): InterfaceOrders {
const url = 'http://oneqbackend.herokuapp.com/api/listas';
this.http.get(url).subscribe((data: InterfaceOrders) => {
this.data_return = data;
console.log(' Valor trabalha bem aqui ==> ' , this.data_return);
});
console.log(' Aqui o valor desaparece ==> ' , this.data_return);
return this.data_return;
}
Inspect:
Value works well here ==> (6) [{... }, {...}, {...}, {...}, {...}, {...}, {...}]
Here the value disappears ==> Undefined
Where he declared data_return?
– LeAndrade
The problem is that subscribe is asynchronous, that is, when you run the function to receive the value it already passes to the line below, and when it finishes fetching the information in the url it assigns the value.
– Wictor Chaves
right. solved. thanks staff.
– Emilio Dami Silva