How do I bind to list of checkbox values with AngularJS?

前端 未结 29 2733
天涯浪人
天涯浪人 2020-11-22 05:20

I have a few checkboxes:





        
29条回答
  •  梦如初夏
    2020-11-22 06:20

    
    

    .

    function SomeCtrl ($scope) {
        $scope.fruits = ["apple, orange, pear, naartjie"];
        $scope.checkedFruits = [];
        $scope.toggleCheck = function (fruit) {
            if ($scope.checkedFruits.indexOf(fruit) === -1) {
                $scope.checkedFruits.push(fruit);
            } else {
                $scope.checkedFruits.splice($scope.checkedFruits.indexOf(fruit), 1);
            }
        };
    }
    

提交回复
热议问题