角度复选框ng-model作为数组

时间:2014-09-25 21:33:33

标签: javascript angularjs angular-ngmodel

我的HTML

    <label>
  <input type="checkbox" name="Communities" ng-model="formData.User.Communities" value="1" id="YOURROLE_0">
  COACH</label>
<br>
<label>
  <input type="checkbox" name="Communities" ng-model="formData.User.Communities" value="2" id="YOURROLE_1">
  ATHLETE</label>
<br>
<label>
  <input type="checkbox" name="Communities" ng-model="formData.User.Communities" value="3" id="YOURROLE_2">
  PARENT</label>

如何指定我获得模型的HTML / Javascript,如下所示。我需要复选框(已选中)作为填充到数组的数组。

.controller('formController', function($scope) {

        $scope.formData = {
            "User": {
                "Communities": [1, 2, 3]
            }
        };

    });

1 个答案:

答案 0 :(得分:2)

核对表模型就是答案

http://vitalets.github.io/checklist-model/