Having trouble retrieving data from a service in an Angular component.
- Here is the service code:
getData(fromDate: string, toDate: string): Observable<WfAverageTime[]>
{
const url ="http://testApi/getData"
return this.http.get<someObject[]>(url);
}
- Now, let's take a look at the component code:
loadData(fromDate, toDate) {
let resp = this.testService.getData(fromDate, toDate);
resp.subscribe((reportData) => {
this.DataSource.data = reportData as someObject[];
this.data1 = reportData;
})
data1
is a class-level variable. Despite being assigned a value, it cannot be accessed as this.data1
in other methods of the class.