[AngularJS]4. Display more object -- ng-repeat
1. In the app.js
file we changed things up a little with a new gems
array. Assign gems to a products
property inside StoreController
.
app.controller('StoreController', function(){ this.products = gems; }); var gems = [ { name: 'Azurite', price: 2.95 }, { name: 'Bloodstone', price: 5.95 }, { name: 'Zircon', price: 3.95 }, ];
2. You know how to display all the products
, don't you? Use the correct directive to display all the products in product row
divs.
<div class="product row" ng-repeat="product in store.products">
<!DOCTYPE html> <html ng-app="gemStore"> <head> <link rel="stylesheet" type="text/css" href="bootstrap.min.css" /> <script type="text/javascript" src="angular.min.js"></script> <script type="text/javascript" src="app.js"></script> </head> <body class="container" ng-controller="StoreController as store"> <div class="product row" ng-repeat="product in store.products"> <h3> {{product.name}} <em class="pull-right">${{product.price}}</em> </h3> </div> </body> </html>
(function() { var app = angular.module('gemStore', []); app.controller('StoreController', function(){ this.products = gems; }); var gems = [ { name: 'Azurite', price: 2.95 }, { name: 'Bloodstone', price: 5.95 }, { name: 'Zircon', price: 3.95 }, ]; })();