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 trialNicolas Hampton
44,638 PointsCopy and paste the todos list for the test
$scope.todos = [
{"name": "clean the house"},
{"name": "water the dog"},
{"name": "feed the lawn"},
{"name": "pay dem bills"},
{"name": "run"},
{"name": "swim"}
];
agreatdaytocode
24,757 PointsThanks for sharing this list :)
Allison Walker
17,137 PointsThanks!
5 Answers
Nicolas Hampton
44,638 Points@underpaidnurse
I think I know what you're referring to, but I'm not sure, so feel free to ask another question.
The variables for ng-model, ng-hide, and ng-show are being declared inside the attributes themselves. So when we write:
<input ng-model="todo.completed" type="checkbox"/>
todo.completed (and todo) are being created inline. Once the element attribute is triggered (in this case, when we click the checkbox) that variable exists in that angular controller's scope, without having to declare it in the controller code itself. Usually it's best practice, from what I understand, to declare these variables in the controller, because if we don't, the attribute does have to be triggered before we will see the model in the scope, but Huston wasn't at the point that he wanted to do that yet at that lesson of the course.
Now we're in ng-repeat, and we are declaring todos in the controller, and attaching it to $scope.todos, so we will have access to it in the scope. But as he explains, when we declare:
<div ng-repeat="todo in todos">
<!--everything we'll repeat is in here, each repeated item will have it's own todo object-->
</div>
we use the $scope.todos variable in the controller to create several cloned objects, all with different child scopes of their own, each with a separate todo object.
Does that answer your question? Let me know, and of course, Happy Coding!
Nicolas
erika harvey
Courses Plus Student 14,540 PointsI think i got it, the last part is us just instantiating a new object. The whole prototypical inheritance?
Zac Heisey
9,918 PointsThanks for sharing the copy/paste stuff included in some of the tutorials! Would be nice to have these code snippets included in the teacher's notes as well.
Tony Brackins
28,766 Pointsthx. Was looking for this lol
Anthony Kelly
15,649 PointsThank you for this! Perhaps it should be added to the video notes so we don't have to search through the Q&As for them ¯_(ツ)_/¯
erika harvey
Courses Plus Student 14,540 Pointserika harvey
Courses Plus Student 14,540 Pointsfor some reason, i didn't see what we did for the app.js to create the model there during the video snafu.What do i need to do for the app.js model syntax? Do i just make an object literal like above in the app js file under .model instead of .controller?