0

I am trying to get the checked boxes in my App using Angular JS

I have something like

<div class="checkbox" ng-repeat="item in items">
    <input type="checkbox" />{{item.name}}   
</div>

How do I get the checked boxes value using angular?

app.controller('test', function(){
    // not sure what do to here...
})

Thanks for the help

FlyingCat
  • 14,036
  • 36
  • 119
  • 198

1 Answers1

0

Here is one way to do this. Might also want to look into using a directive.

http://jsfiddle.net/Sj3nG/

var app = angular.module('checkboxApp', []);

app.controller('CheckboxCtrl', function ($scope) {
    $scope.color_list = [{
        name: 'Red',
        selected: false
    }, {
        name: 'Blue',
        selected: false
    }, {
        name: 'Yellow',
        selected: false
    }];
    $scope.colors = [];

    $scope.$watchCollection('color_list | filter:{selected:true}', function (color) {
        $scope.colors = [];
        angular.forEach(color, function (c) {
            if (c.selected) {
                $scope.colors.push({
                    color: c.name
                });
            }
        });
    });
});
Rob
  • 1,840
  • 2
  • 12
  • 19