How to get an array of checkboxes in Angular JS?

I have some checkboxes in HTML:

<input type="checkbox" name="type[]" value="3">
<input type="checkbox" name="type[]" value="4">
<input type="checkbox" name="type[]" value="5">

      

How can I get all selected values ​​in Angular JS?

I tried to add for headphone input: ng-model="type[]"

+3


source to share


1 answer


Try the following:

<div ng-controller="MyCheckbox" 
 ng-init="checkboxes = {1: true, 2: false, 3: true, 4: false}">
    <input type="checkbox" ng-model="checkboxes.1">1
    <input type="checkbox" ng-model="checkboxes.2">2
    <input type="checkbox" ng-model="checkboxes.3">3
    <input type="checkbox" ng-model="checkboxes.4">4
    <br>{{checkboxes}}
</div>

      



JSFIDDLE DEMO

+1


source







All Articles