I have made a little fiddle of what I am doing, although it won't work in fiddle oddly, but does incrementally add a like in my version: /
function($scope) {
var hasLiked = false;
$scope.likeClicked = function() {
if( hasLiked === false ){
$scope.likeCount = $scope.likeCount + 1;
}
hasLiked = true;
if (hasLiked === true) {
$scope.liked = 'Unlike';
}
};
});
What I am trying to do is: Add a 'like' > disable 'like' and replace with 'unlike' > on next click of element, remove the like
Please help!
Thanks,
JP
I have made a little fiddle of what I am doing, although it won't work in fiddle oddly, but does incrementally add a like in my version: http://jsfiddle/LQFrv/
function($scope) {
var hasLiked = false;
$scope.likeClicked = function() {
if( hasLiked === false ){
$scope.likeCount = $scope.likeCount + 1;
}
hasLiked = true;
if (hasLiked === true) {
$scope.liked = 'Unlike';
}
};
});
What I am trying to do is: Add a 'like' > disable 'like' and replace with 'unlike' > on next click of element, remove the like
Please help!
Thanks,
JP
Share Improve this question asked Apr 9, 2013 at 12:44 JohnRobertPettJohnRobertPett 1,1834 gold badges22 silver badges37 bronze badges 1-
use a browser console to look at errors. Fiddle immediately throws error
SyntaxError: function statement requires a name
and you have nong-controller
in fiddle html. What is the question? – charlietfl Commented Apr 9, 2013 at 12:59
1 Answer
Reset to default 4HTML:
<body ng-app ng-controller="Ctrl">
<a ng-click="likeClick()" ng-init="liked='Like'; likeCount=0">
{{liked}} {{likeCount}}
</a>
</body>
JS:
function Ctrl($scope) {
var hasLiked = false;
$scope.likeClick = function () {
if (!hasLiked) {
hasLiked = true;
$scope.liked = 'Unlike';
$scope.likeCount += 1;
} else {
hasLiked = false;
$scope.liked = 'Like';
$scope.likeCount -= 1;
}
};
}
Working fiddle: jsfiddle/LQFrv/4/
Hope that helps!
edit: messed up with the link, it lead to another fiddle, sorry, now it should be correct!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745423611a4627076.html
评论列表(0条)