我的代码中似乎出现了问题,我无法分辨它是什么。当我点击运行时,我收到一条错误消息:
"在元素上,确保使用ng-click调用minusOne() 。功能"
我认为某处可能存在语法错误,但我无法告诉。
查看代码
<div class="rating">
<p class="likes" ng-click="plusOne($index)">+ {{ product.likes }} </p>
<p class="dislikes" ng-click="minusOne($index)">- {{ product.dislikes }}</p>
</div>
控制器代码
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',
likes: 0,
dislikes: 0
}, {
name: 'Program or be Programmed',
price: 8,
pubdate: new Date('2013', '08', '01'),
cover: 'img/program-or-be-programmed.jpg',
likes: 0,
dislikes: 0
}, {
name: 'Harry Potter & The Prisoner of Azkaban',
price: 11.99,
pubdate: new Date('1999', '07', '08'),
cover: 'http://upload.wikimedia.org/wikipedia/en/b/b4/Harry_Potter_and_the_Prisoner_of_Azkaban_(US_cover).jpg',
likes: 0,
dislikes: 0
}, {
name: 'Ready Player One',
price: 7.99,
pubdate: new Date('2011', '08', '16'),
cover: 'http://upload.wikimedia.org/wikipedia/en/a/a4/Ready_Player_One_cover.jpg',
likes: 0,
dislikes: 0
}];
$scope.plusOne = function (index) {
$scope.products[index].likes += 1;
};
$scope.minusOne = function (index) {
$scope.products[index].dislikes -= 1;
};}]);
答案 0 :(得分:4)
在控制器代码的最底部,它应该尝试这个:
$scope.products[index].dislikes += 1;
答案 1 :(得分:0)
尝试在div上使用它,而不是p标签? (如果需要,将每个p包装在div中)