I'm struggling to set a value to an array within an Observable using a Lambda expression.
Here is a snippet of my class:
usuarios: Usuario[];
Currently, I am utilizing an Http service for injection.
Within one of my functions, I have the following code:
getUsuarios(): Usuario[] {
this._http.get("http://localhost:3000/db").map(data => data.json()).subscribe(data => {
this.usuarios = data["Usuarios"];
console.log(this.usuarios);
});
console.log(this.usuarios);
return this.usuarios;
}
Strangely enough, the first console log output (within the lambda expression) shows the data correctly in the console. However, upon another attempt to log it outside the lambda expression, this.usuarios
appears empty and undefined.
Any insights into why this behavior is occurring?