Skip to content

Instantly share code, notes, and snippets.

@itswadesh
Last active March 27, 2017 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itswadesh/12c9a1c7a6e89c15591a5fef8c9823bf to your computer and use it in GitHub Desktop.
Save itswadesh/12c9a1c7a6e89c15591a5fef8c9823bf to your computer and use it in GitHub Desktop.
var app = angular.module('myApp',[]);
app.controller('votingCtrl', function($scope, $http) {
$http.post('ajax/getPosts.php').success(function(data){
$scope.posts = data;
});
$scope.upVote = function(post){
post.votes++;
updateVote(post.id,post.votes);
};
$scope.downVote = function(post){
post.votes--;
updateVote(post.id,post.votes);
};
function updateVote(id,votes){
$http.post('ajax/updateVote.php?id='+id+'&votes='+votes);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment