Search code examples
javascriptangularjscheckboxcheckboxlist

Angular Get Selected CheckBoxes


I have a list of dynamically filled checkboxes using angular.

 <div ng-repeat="X in XList">
     <label>{{X.Header}}</label>
     <input type="checkbox" name="X" value="{{X.Item.Id}}" />
     <p>{{X.Header}}</p>
 </div>

I want a method to retrieve a list of all the selected checkboxes. Usually I'd use

 $('input[name=checkboxlist]:checked').each(function()
{
}

But this is not acceptable with angular .... So is there an appropriate Method to do so?


Solution

  • here is the implemented plunker

     <input type="checkbox" ng-model="selected[record.Id]"> {{record.Id}}
    
     $scope.ShowSelected = function() {
      console.log($scope.selected);
      alert(JSON.stringify($scope.selected));
    };