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 trialJonathan Grieve
Treehouse Moderator 91,253 PointsAngular Expression doesn't display
I've got a bit of a mystery here which I'm hoping some in the know about Angular will be able to resolve.
It's a simple example of using ng-repeat to display a block of information 3 times. There's 3 values in an object of the controller js file. Name, Description and Price. But price won't show up. Any ideas why?
http://www.jonniegrieve.co.uk/jg-lab.co.uk/codecademy/angular2/index.html
<!doctype html>
<html>
<head>
<link href="https://s3.amazonaws.com/codecademy-content/projects/bootstrap.min.css" rel="stylesheet" />
<link href='https://fonts.googleapis.com/css?family=Playfair+Display:400,400italic,700italic|Oswald' rel='stylesheet' type='text/css'>
<link href="main.css" rel="stylesheet" />
<script src="angular.min.js"></script>
</head>
<body ng-app="PizzaPlanetApp">
<div class="header">
<h1><span>Pizza</span><span>Planet</span></h1>
</div>
<div class="main" ng-controller="MainController">
<div class="container">
<h1>Specials for {{ today | date }}</h1>
<h2>Appetizers</h2>
<div class="row">
<div class="item col-md-9" ng-repeat="appetizer in appetizers">
<h3 class="name"> {{ appetizer.name }} </h3>
<p class="description">{{ appetizer.description }} </p>
</div>
<div class="price col-md-3">
<p class="price">{{ appetizer.price }}</p>
</div>
</div>
</div>
</div>
<div class="footer">
</div>
<!-- Modules -->
<script src="app.js"></script>
<!-- Controllers -->
<script src="MainController.js"></script>
</body>
</html>
var app = angular.module("PizzaPlanetApp",[]);
app.controller('MainController', ['$scope', function($scope) {
$scope.today = new Date();
$scope.appetizers = [
{
name: 'Caprese',
description: 'Mozzarella, tomatoes, basil, balsmaic glaze.',
price: 4.95
},
{
name: 'Mozzarella Sticks',
description: 'Served with marinara sauce.',
price: 3.95
},
{
name: 'Bruschetta',
description: 'Grilled bread garlic, tomatoes, olive oil.',
price: 4.95
}
];
}]);
1 Answer
Chris Shaw
26,676 PointsHi Jonathan,
You appear to have your ng-repeat
attribute on the wrong line, to me it makes sense to have it on the .row
above since you're using columns, try the below.
<div class="row" ng-repeat="appetizer in appetizers">
<div class="item col-md-9">
<h3 class="name"> {{ appetizer.name }} </h3>
<p class="description">{{ appetizer.description }} </p>
</div>
<div class="price col-md-3">
<p class="price">{{ appetizer.price }}</p>
</div>
</div>
Hope that helps.
Jonathan Grieve
Treehouse Moderator 91,253 PointsJonathan Grieve
Treehouse Moderator 91,253 PointsSmashing! This worked thanks!
The original task wasn't showing up properly when I had the
ng-repeat
where you suggested it. None of the expressions were showing up. So I moved it and then the name and description showed up but not the price. How odd but it looks like we've found the answer. :)