I have 2 functions in ngOninit
ngOnInit(){
this.getRowData();
this.getWrapperGridData();
}
GetRowData() is used to subscribe to a service and it looks like this
getRowData() {
this.showDataServiceSubscription = this.heroService.showData().subscribe((data) => {
this.onlineData = data;
console.log('onlineData 1',this.onlineData);
})
}
In getWrapperGridData, I am calling this.onlineData again like this
getWrapperGridData(){
console.log('onlineData',this.onlineData);
}
The problem is I am getting the result of onlineData inside getRowData method as it is written inside subscribe but I am getting undefined inside getWrapperGridData. How do we fix this?