使用angularjs将复选框设置为已选中

Nis*_*sin 7 angularjs angularjs-directive angularjs-scope

我有一些复选框,它们的值在数据库中是'Y'或'N'作为枚举.为了进行更新我必须检查所有复选框.如何查看复选框已选中.这是复选框的代码

<label class="radio-inline">
  <input type="checkbox"  ng-model="newItem.have_voter_id"  value="have_voter_id" /><?php echo $this->lang->line('label_voter_id'); ?>
</label>
<label class="radio-inline">
  <input type="checkbox"   ng-model="newItem.have_passport" value="passport" /> <?php echo $this->lang->line('label_passport'); ?>
 </label>
Run Code Online (Sandbox Code Playgroud)

这是查看和更新​​的功能

 $scope.edit = function(id,family_id) {

    $scope.action = 'update';
    FamilyMem.get({id:id,family_id:family_id}, function (response) { // success            
        $scope.newItem = response.data; // store result to variable            
          $("#myModal").modal('show');
        }, function (error) { // ajax loading error
            Data.errorMsg(); // display error notification
            //$scope.edit = false;
        });
  };
Run Code Online (Sandbox Code Playgroud)

并编辑按钮

  <a href="" class="btn btn-magenta btn-sm" ng-click="edit(family_member.id,family_member.family_id)">
Run Code Online (Sandbox Code Playgroud)

dev*_*evo 17

使用ng-checked的的复选框,

<label class="radio-inline">
  <input type="checkbox"  ng-model="newItem.have_voter_id"  value="have_voter_id" ng-checked="newItem.have_voter_id=='Y'"/><?php echo $this->lang->line('label_voter_id'); ?>
</label>

<label class="radio-inline">
  <input type="checkbox"   ng-model="newItem.have_passport" value="passport" ng-checked="newItem.have_passport=='Y'"/> <?php echo $this->lang->line('label_passport'); ?>
</label>
Run Code Online (Sandbox Code Playgroud)