사이트 방문자가 자신이 좋아하는 게임에서 투표를 할 수있는 투표 위젯이 있습니다. 그러나 방문객은 네거티브에도 투표 할 수 있습니다!최소 0의 투표 위젯
범위 내 game
객체의 현재 voteCount
가 0
로 설정되어있는 경우 예를 들어, 사용자는 아래쪽 화살표를 따라 올 수 -1
로 변경. 어떻게 이런 일이 일어나지 않게 할 수 있습니까?
투표를하기 전에 수표를 사용하여 수동으로 할 수 있지만이를 수행 할 각도 필터가 없습니까?
또한 사용자가 끝없는 표 대신 단일 표를 허용하는 가장 빠른 방법은 무엇입니까? 쿠키가 가장 빠른 방법일까요? 또는 HTML5의 LocalStorage
?
CTRL 코드
myApp.controller('VotingCtrl', function($scope){
$scope.games = [
{
name: 'Watch Dogs',
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ut felis dapibus, bibendum dui eu.',
imgUrl: 'img/watchdogs.jpg',
voteCount: 0
},
{
name: 'Thief',
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ut felis dapibus, bibendum dui eu.',
imgUrl: 'img/thief.jpg',
voteCount: 0
},
{
name: 'Fifa 2014',
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ut felis dapibus, bibendum dui eu.',
imgUrl: 'img/fifa2014.jpg',
voteCount: 0
}
]
$scope.voteUp = function(game) {
game.voteCount += 1;
};
$scope.voteDown = function(game) {
game.voteCount -= 1;
};
});
AngularJS 필터 란 무엇입니까? AngularJS는 프레임 워크로서 여러분을위한 함수 (이 경우에는'voteDown')를 호출합니다. -이 함수에 어떤 논리가 들어 있는지 알려줍니다. 따라서 투표가 부정적이지 않도록 보장하는 함수를 작성하십시오! – callmekatootie