how to create up/down voting function in angularjs

后端 未结 2 1360
不知归路
不知归路 2021-02-11 03:12

Hey guys may i know how can i create a up/down voting function in angularjs ? i want to make it to something similar to stackoverflow or reddit. i found a Jquery plugin https:/

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-11 03:25

    It should be simple to make something like this.
    Here's a simple example:

    JS:

    var app = angular.module('voteApp', []);
    
    app.controller('MainCtrl', function ($scope) {
        $scope.upVote = function () {
            $scope.vote++;
        }
    
        $scope.downVote = function () {
            $scope.vote--;
        }
    
        $scope.vote = 0;
    });
    

    Fiddle.

提交回复
热议问题