Angular Get Selected CheckBoxes

Sana Joseph picture Sana Joseph · Aug 7, 2013 · Viewed 26.6k times · Source

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?

Answer

Vinod Louis picture Vinod Louis · Aug 7, 2013

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));
};