6. ng-repeart I - part 2


#1



https://www.codecademy.com/en/courses/learn-angularjs/lessons/your-first-app/exercises/your-first-app-ng-repeat-i?action=resume

This is my code for the MainController:

app.controller('MainController', ['$scope', function($scope) {
$scope.title = 'This Month\'s Bestsellers';
$scope.promo = 'The most popular books this month.';
$scope.products = {
[
{
name: 'The Book of Trees',
price: 19,
pubdate: new Date('2014', '03', '08'),
cover: 'img/the-book-of-trees.jpg'
},
{
name: 'Program or be Programmed',
price: 8,
pubdate: new Date('2013', '08', '01'),
cover: 'img/program-or-be-programmed.jpg'
}
]
}
}]);

The error message is:
Oops! The test returned an error. Maybe you have a syntax error, or a typo. Hide error.
SyntaxError: Unexpected token '[', at /home/ccuser/workspace/angularjs-your-first-app/js/controllers/MainController.js:5
Run

HOWEVER, I did what the instructions told me to do for part 2. I added the scope and literally copied and pasted the provided code there to minimize any typing errors.
Please Help! What did I do wrong?


#2

$scope.products = {
    [ 
      { 
        name: 'The Book of Trees', 
        price: 19, 
        pubdate: new Date('2014', '03', '08'), 
        cover: 'img/the-book-of-trees.jpg' 
      }, 
      { 
        name: 'Program or be Programmed', 
        price: 8, 
        pubdate: new Date('2013', '08', '01'), 
        cover: 'img/program-or-be-programmed.jpg' 
      } 
    ]
  }

$scope is meant to be an array.

$scope = [
  {},
  {},
  {}
];

#3

Ohhh... I see. Thanks!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.