加载时选中复选框的值

问题描述 投票:0回答:1

默认情况下,需要选中/选中复选框值。尝试了以下不起作用的方法。

html

 <form [formGroup]="form">
 <label><input type="checkbox" class="form-check-input" [(ngModel)]="organism.active" formControlName="active" >Selected</label>
</form>

ts

constructor() { this.getFromGroup(); }
 private getFromGroup() {
    this.form = this.formBuilder.group({
        'active': new FormControl(true),
    })

  }

甚至尝试过此

 this.form.patchValue({
      'active': true
    })
angular angular7 angular8
1个回答
0
投票

只需将属性添加到输入checked="checked",它将起作用

© www.soinside.com 2019 - 2024. All rights reserved.