I have a list, simple - string[]. I generate checkbox for every item of that list. Then I create FormControls:
this.list.map((item) => {
this.form.addControl(item, new FormControl(false, Validators.required))
})
But I want to add a Validator to control the allowed number of checked checkboxes, so I assume I could do this if I move those FormControls into the FormGroup, so I try something like:
constructor(private fb:FormBuilder) {
this.form = this.fb.group({
input1Ctrl: ['', Validators.required],
input2Ctrl: ['',Validators.required],
checkboxGroup : new FormGroup({})
})
this.list.map((item) => {
this.form.checkboxGroup.addControl(item, new FormControl(false, Validators.required))
})
But that gives:
Supplied parameters do not match any signature of call target. Property 'checkboxGroup' does not exist on type 'FormGroup'.
How should I do it?
Access
checkboxGrouplikethis.form.controls['checkboxGroup'].EDIT : Created plunker for the above
https://plnkr.co/edit/nxo52y?p=preview