Javascript AngularJS:按下复选框

Javascript AngularJS:按下复选框,javascript,angularjs,Javascript,Angularjs,我正在尝试解决如何使用AngularJS将通过表单提交的复选框推送到名为services的对象 这些是我的目标: $scope.sectors = [ 'health', 'social', 'education' ]; $scope.services = [ { 'name': 'Hernia Repair', 'sectors': { 'health': true } }, { 'name': 'Cance

我正在尝试解决如何使用AngularJS将通过表单提交的复选框推送到名为
services
的对象

这些是我的目标:

$scope.sectors = [ 'health', 'social', 'education' ];

$scope.services = [
      {
        'name': 'Hernia Repair',
        'sectors': { 'health': true }
      },
      {
        'name': 'Cancer',
        'sectors': { 'health': true, 'social': true, 'education': true }
      },
  ];
这是我的表格:

<form role="form" ng-submit="createService(newService)">
  <div class="form-group">
    <label for="serviceName">Name of Service</label>
    <input id="serviceName" type="text" class="form-control" ng-model="newService.name" placeholder="Name of Service">
  </div>

  <div class="form-group">
    <label for="serviceName">Another</label>
    <input id="serviceName" type="text" class="form-control" ng-model="newService.another" placeholder="Name of Antoher">
  </div>

  <div class="checkbox-inline" ng-repeat="sector in sectors">
    <label>
      <input type="checkbox" name="optionsRadios" id="{{sector}}" value="{{sector}}" ng-model="service.sectors[sector]">
      {{sector}}
    </label>
  </div>

  <button type="submit" class="btn btn-default">Submit</button>
</form>
名称
似乎被添加到
服务
列表中,但
扇区
没有。谁能给我指出正确的方向,或者解释我可能做错了什么


感谢您的帮助。提前谢谢

使用
newService.sectors[sector]
而不是
service.sectors[sector]
为您的ng型号的收音机按钮输入一个打字错误。。标记关闭。@friedi@PSL将其更改为
newService.sectors[sector]
。我如何检查这是否被正确地添加到
服务中
??
function createService(service) {
    $scope.services.push(service);
}

$scope.createService = createService;