您好,我从 API 命中获取对象数组,该对象数组必须分配给 formGroup。我尝试过使用 formGroup 绑定,但它检测到真/假值,但它不会给我对象数组中更改的真/假值,而是只给我真/假,而且我在另一个数组中也有日期输入字段,它也不会检测真/假值或更改的值。如果我写的代码是错误的,那么请纠正我并帮助我以有效的方式编写。
帮助表示赞赏。
演示:演示
TS:
private settingsInfoForm() {
if (!this.agentDetailsList) {
// Add
this.agentSettingsInfoForm = this.FB.group({
agentToogles: this.FB.array(this.detailsToggle.map(x=> x.boolValue)),
restrictionsInfo:this.FB.array(this.Restrictions.map(x=>x.boolValue))
});
} else {
// Edit
if (this.agentDetailsList) {
this.detailsToggle = this.agentDetailsList
this.agentSettingsInfoForm = this.FB.group({
agentToogles: this.FB.array(this.detailsToggle.map(x=>x.boolValue)),
restrictionsInfo:this.FB.array(this.Restrictions.map(x=>x.boolValue))
})
}
this.agentSettingsInfoForm.valueChanges.subscribe(data => {
this.formEdit = true;
console.log('agentSettingsInfoForm', this.formEdit)
})
}
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<form [formGroup]= "agentSettingsInfoForm">
<div class="row row-cols-2" formGroupName="agentToogles">
<div class="col" *ngFor="let toggleValue of detailsToggle;let i = index">
<div class="custom-control custom-switch mb-3">
<input type="checkbox" [formControlName]="i" …Run Code Online (Sandbox Code Playgroud)