Well done! You got both books in
$scope.products to show up in the view. How does it work?
- In the controller, we used
products to store an array containing two objects.
- Then in the view, we added
<div ng-repeat="product in products">. Like
ng-repeat is a directive. It loops through an array and displays each element. Here, the
ng-repeat repeats all the HTML inside
<div class="col-md-6"> for each element in the
In this way,
ng-repeat shows both products in the
$scope.products array. Instead of writing the same HTML twice as before, we just use
ng-repeat to generate the HTML twice.