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

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Angular: I don't understand the question in the context of the video.

Here's the code as I've written so far. The question asks,

Write the HTML to output an unordered list that iterates over the array bowlOfFruit and outputs the property name for each array element as a list item.

But i've been through the video twice and i can't seem to make the connection between the challenge and the video.

To iterate, I can only assume it means the ng-repeat directive and to output the correct valur you'd type {{user.nbowlOfFruit}}. But what am I missing?

Thanks

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">{{name.bowlOfFruit}}</li></ul>

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

2 Answers

Ryan Foote
Ryan Foote
14,435 Points

You're very close. In your ng-repeat directive, since you are saying name in bowlOfFruit the expression would be {{name.name}}.

A better option for your directive might be fruit in bowlOfFruit so the expression would be {{fruit.name}}.

Example

maratfaizov
maratfaizov
14,228 Points

I was bit struggling with it too, found solution here: https://docs.angularjs.org/api/ng/directive/ngRepeat.

Correct answer will be:

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