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 trialJason S
16,247 Points$scope.todos is undefined since the data is received after it's been created ?
hi he says this in the video but I do not quite understand what that means. Can someone explain in more detail?
4 Answers
Erik Nemesis
13,356 PointsI didn't see the video but it probably refers to asynchronous data.
Because this is an asynchonous operation, that means that the contents will be available at a later time (it could be in a second or in a few minutes depending on external factors such as connection bandwidth and such), therefore when $scope.todos is created, it is empty at first.
Jason S
16,247 Pointsokay. so in reference to the video, I am thinking that the $http.get is taking a long time, therefore the response.data is also taking a long time, and dataService.getTodos is undefined because there is no data.
Charles Cloud
6,134 PointsMy understanding is that the variable is created before the response has been returned, therefore it is set to undefined.
Şahin Özdoğru
917 PointsI can understand that the variable is undefined at first. But what happens after function returns something. Should not it be defined?