Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript AngularJS Basics (1.x) Using Angular's Built In Directives Using ng-repeat to inject HTML for every data element

Nicolas Hampton
Nicolas Hampton
44,625 Points

Copy 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"}
    ];

for 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?

Thanks for sharing this list :)

Thanks!

5 Answers

Nicolas Hampton
Nicolas Hampton
44,625 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

I think i got it, the last part is us just instantiating a new object. The whole prototypical inheritance?

Zac Heisey
Zac Heisey
9,918 Points

Thanks 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.

thx. Was looking for this lol

Thank 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 ¯_(ツ)_/¯