I am using Angular 2 for creating a webapp and ran into a weird problem which is worth understanding.
I am trying to print the value of an object right after assigning a new value and a bit later. Following is the code:
do {
this._sharedService.readServerStatus().subscribe(res =>
{
this.surveyStatus = JSON.parse(JSON.stringify(res));
console.log(this.surveyStatus);
});
console.log("ne");
console.log(this.surveyStatus);
}
while(this.surveyStatus.isBusy());
In this code, surveyStatus is an object which I wish to print to the console. Following is the output from the browser console:
Object {serverBusy: 1, terminate: 0}
ServerStatus {}
The first one is printed out as expected, while when I read it outside the loop, something weird happens to the object. Can someone help me understand what's going on.