Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AngularJS Basics (1.x) Services in Angular Using Services To Get Data

I don't understand response.data @3:45

Instructor doesn't explain response.data, just simply plugs it in. Where is .data coming from? Is it a built-in Angular method? What is it's purpose?

2 Answers

Ryan S
Ryan S
27,276 Points

Hi Jay,

When calling Angular's $http.get() method, the server will respond with a 'response' object, provided the request was successful.

This 'response' object has a few properties that you can access, one of which is "data". This data property will contain the data of the response, i.e., the JSON object that you had requested from the server.

Other properties of the response object are: config, headers, status, and statusText which can be accessed in the same way as the data.

Hope this clears things up.

Thank you, was reading up on it. The response from the server is an object that has properties. data is just one of the properties it has. I've posted a link for more info and properties.

https://www.w3schools.com/angular/angular_http.asp

olu adesina
olu adesina
23,007 Points

this is extremely helpful thanks @jaycode and ryan s