I am using Angular framework and API service to receive data from a table from my database.
My purpose is to fill a JSON with the data received with my apiService.getData() and my subscribe() functions.
When i do
console.log(this.observance)
inside the subscribe(), it displays all my table, as it is supposed to do.
But when I do
console.log(this.observance)
just after the subscribe(), in the last line, my console says that my variable this.observance is 'undefined'. Do you know why? Thanks! (sorry for my bad English)
Here is my code:
this.apiService.getData("observance/patient/" + this.patient.id).subscribe(
x => {
this.observance = JSON.parse(x.body);
},
err => {
console.log(this.observance);
console.log("Aucune observance récupéré.");
},
() => console.log(this.observance)
)
console.log(this.observance);