I am fetching an object from node server using a angular 6 service.
getMasterObj () {
this.http.get(this.url1).subscribe(
(data) =>{
this.masterChartObj1 = data;
console.log(this.masterChartObj1) // data is getting printed
})
console.log(this.masterChartObj1) // undefined
}
In same classs I have defined an object as
public masterChartObj1;
I am initializing that object with the data received in subscribe method. as checked in console.log it is printed but same is undefined outside subscriber method.
I have tried same in another way also, but still same output.
getMasterObj () {
let parent_scope = this;
this.http.get(this.url1).subscribe(
(data) =>{
parent_scope.masterChartObj1 = data;
console.log(parent_scope.masterChartObj1) // data is getting printed
})
console.log(this.masterChartObj1) // undefined
}
Please let me know, if I am doing anything wrong...