如何获得Angular JS中的复选框数组?

时间:2015-04-20 12:37:27

标签: angularjs

我在HTML中有一些复选框:

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

如何在Angular JS中获取所有选定的值?

我尝试添加earch输入:ng-model="type[]"

1 个答案:

答案 0 :(得分:1)

试试这个:

<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