我使用带有反应形式的FormArray列出复选框。它已呈现,但未显示为checked。我已经设置了默认1复选框,但仍未选中。我不知道我的代码有什么问题吗?有人可以帮忙吗? 我的html
<div class="checkbox" formArrayName="couponDay" *ngFor="let day of promotionGenerateForm.controls['couponDay'].controls; let dayIndex = index">
<label><input type="checkbox" [formControlName]="dayIndex">{{dayArr[dayIndex].name}}</label><span></span>
</div>
我的ts代码:
private formInit = () => {
const controls = this.dayArr.map(c => new FormControl(false));
controls[0].setValue(true);
this.promotionGenerateForm = new FormGroup({
['couponType']: new FormControl(0),
['couponAmount']: new FormControl(''),
['couponExpireDate']: new FormControl(''),
['couponDay']: new FormArray(controls),
});
};