我的代碼似乎出了點問題,我不知道它是什麼。當我點擊運行,我得到一個錯誤,指出:如何解決「確保使用ng-click來調用該函數」錯誤
「在元素,確保使用NG-點擊調用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;
};}]);
你確定這個視圖代碼是由你的mainController控制? (ng-controller或者$ routeProvider) –
你可以提供一個plunker(http://plnkr.co/)嗎? –