Angular 2 Error while fetching data from Django Rest API

Hey Campers, I need some help with fetching data for my Angular 2 + Django Application.
The detailed problem is mentioned here…

Anyone with the expertise in topics: Django, Angular, REST
Please consider adding some of your valuable knowledge, it will help me to deploy my first Major Application. Thanks :slight_smile:

The HttpClient already returns json, so maybe the mapping causes an error.

Can you detail this please

This part:

.map((res) => this.extractData(res.json()))

is not necessary (and might cause the error) because you are using the HttpClient which already returns the json (instead of the whole response).

Also, you are passing res.json() to the function. So the res parameter of extractData can never be of type Response.

so should it be
.map((res) => this.extractData(res))

And what is the difference of using Http and HttpClient

HttpClient is an updated version of Http. So with Http it should indeed be: .map((res) => this.extractData(res)), but with HttpClient you can completely remove that part.

1 Like

also what datatype shoud I give to extractData?

I am not sure what you are trying to achieve with extractData, you can simply use .map(res => res.json()) if you want to map the response to json.

And what exactly is the error you are getting?

Thank you so much, it’s returning the desired result now. If you are on StackOverflow feel free to answer it. I will upvote there.

1 Like

Not on SO.

EDIT: Note that you were already using HttpClient.