Can anyone assist me with a minor issue I'm facing related to Angular 6 HttpClient? I seem to be encountering an obstacle with the response from my REST API calls. Utilizing HttpClient, I have a function that retrieves a list of all users (referred to as leads in my case).
fetchLeadsList(){
return this.http.get('http://localhost:3000/api/leads')
.pipe(
map(data => {
console.log(data);
return data;
}));
}
Within the OnInit
of my component, I invoke this endpoint like so:
this.leadsService.fetchLeadsList()
.subscribe(response => {
console.log(response, 'leadsList');
this.leadsList = response.data; // leadList is an empty array
});
The list of leads appears as follows: https://i.sstatic.net/Sb1Dy.png
However, when trying to extract the response data within the component as mentioned above (this.leadsList = response.data), I encounter the following error:
ERROR TS2339: Property 'data' does not exist on type 'Object'.
Considering that the image shows the presence of the data property, why am I receiving this error?
In addition, I can successfully display the list in the view! Is there something crucial that I might be overlooking?