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 An Introduction to Two-Way Data Binding Lists

Daniel Hildreth
Daniel Hildreth
16,170 Points

I need help with the AngularJS challenge after the video on Lists.

So I need help with the AngularJS challenge. It asks me to "Write the HTML to output an unordered list, or <ul>, that iterates over the array bowlOfFruit and outputs the property name for each array element as a list item." I cannot seem to figure out how to do this. Can someone help me? The tutorial videos were not very clear as to the structure of the content and in understanding the concepts of what went where.

index.html
<!DOCTYPE html>
<html ng-app="myApp">
<head>
  <title>Angular.js</title>
  <script src="js/angular.js"></script>
  <script src="app.js"></script>
</head>
<body ng-controller="myController">
<ul>
  <li ng-repeat="name in bowlOfFruit" ng-class="name.bowlOfFruit" />
  {{bowlOfFruit.name}}

</body>
</html>
app.js
angular.module('myApp', [])
.controller('myController', function ($scope, $http) {
  $scope.bowlOfFruit = [
    {name: 'Apple'},
    {name: 'Pear'},
    {name: 'Orange'}
  ];
});

1 Answer

So your <li> with the ng-repeat is on the right track. The bowlOfFruit looks to be an array of objects. When you ng-repeat( x in array) each individual array item will be iterated through, and named 'x'. In this case x will be an object, so you can address its properties with dot-notation like this: x.key, or in your example you would use the following:

<li ng-repeat="fruit in bowlOfFruit" />
  {{fruit.name}}
</li>

be sure to close your li and ul elements