In my Angular 2 project, I have a function that retrieves data from a database using an API. I've created a function that stores the data successfully in a variable named "ReqData", which is of type "any".
this._visitService.getchartData().subscribe(data =>
{
this.ReqData = data;
console.log("ISubscribe", this.ReqData );
});
console.log("OSubscribe", this.ReqData );
this.ImpoData = this.getData(this.ReqData);
The issue I'm facing is that while the data can be accessed within the subscribe function, trying to access it outside of the subscribe results in getting undefined as output. Is there a way to also use the data outside of the subscribe function?