I have a scenario where I need to disable multiple checkboxes in a FormArray when the page loads. Despite my attempts to implement this, it hasn't been successful so far. Can someone provide guidance on how to achieve this?
.ts file
public myForm: FormGroup = new FormGroup({
name: new FormControl('', Validators.required),
specialized: new FormArray([]),
});
ngOnInit(): void {
this.companyForm.controls['specialized'].disable();
}
get myFormArray() {
return this.myForm.controls.specialized as FormArray;
}
private addCheckboxesToForm() {
this.specilizedArea.forEach(() => this.myFormArray.push(new FormControl(false)));
}
.html file
<form [formGroup]="myForm">
<div class="form-check col-md-6"
*ngFor="let order of myFormArray.controls; let i = index">
<label formArrayName="specialized">
<input type="checkbox" [formControlName]="i">
{{specilizedArea[i]?.description}}
</label>
</div>
<button (click)="saveCompany()"> ADD</button>
</form>