9. ng-click 1


#1

Is this the right code?
$scope.plusOne =
{
function(index) {
$scope.products[index].likes += 1;
};


#2

By the way, it doesn't work in the MainController.


#3

In your code, you have an unnecessary curly bracket. just before the function(index). IF you remove this, it should run smoothly.

P.S. practice indentation :1234:


#4

Hello,
you have to remove extra curly brackets. please see below code

$scope.plusOne = function(index) {
$scope.products[index].likes += 1;
};


#5

I don't understand why this isn't passing, it just hangs then gives me a vague port in use error

app.controller('MainController', ['$scope', function($scope) {
$scope.title = 'Titles Smell Bad';
$scope.promo = 'Your Gonna Absolutely Love This!';
$scope.products = [
{
name: 'The Book of Trees',
price: 19,
likes: 0,
pubdate: new Date('2014', '03', '08'),
cover: 'img/the-book-of-trees.jpg',

},
{
name: 'Program or be Programmed',
price: 8,
likes: 0,
pubdate: new Date('2013', '08', '01'),
cover: 'img/program-or-be-programmed.jpg' ,

},

{
name: 'Bob Plays The Banjo',
price: 3.99,
likes: 0,
pubdate:('2014', '02' , '21') ,

},

{
name: 'Stuart Watches Bob',
price: 6.99,
likes: 0,
pubdate:('2015', '01' , '31') ,
}

]

}]);

Weird Error : [33mWARN [karma]: [39mPort 9876 in use


#6

you don't need the comma after the last property in each of your objects. So your code should look like:

app.controller('MainController', ['$scope', function($scope) {
$scope.title = 'Titles Smell Bad';
$scope.promo = 'Your Gonna Absolutely Love This!';
$scope.products = [
{
name: 'The Book of Trees',
price: 19,
likes: 0,
pubdate: new Date('2014', '03', '08'),
cover: 'img/the-book-of-trees.jpg' //notice how i removed the comma here

},
{
name: 'Program or be Programmed',
price: 8,
likes: 0,
pubdate: new Date('2013', '08', '01'),
cover: 'img/program-or-be-programmed.jpg' //and here

},
{
name: 'Bob Plays The Banjo',
price: 3.99,
likes: 0,
pubdate:('2014', '02' , '21') //and here
//where is your 'cover' here??
},
{
name: 'Stuart Watches Bob',
price: 6.99,
likes: 0,
//where your 'cover' here?? , // you need that comma after adding your cover property
pubdate:('2015', '01' , '31') // and here
}

]

}]);

also, your number of properties is inconsistent for your objects, you may want to search for images online and include the image address in your cover so you can have that extra property and a value for it.
Let me know if it works.
Cheers :slight_smile: