I am creating a form in angular2 and typescript. I am trying to add a list of checkboxes dynamically and it does not work for me, where is my error?
Template Code:
<div formArrayName="categories"> <div class="form-group" *ngFor="let category of updateDetailsForm.controls.categories.controls; let i = index"> <label> <input type="checkbox" formControlName="{โ{i}}"> {โ{category.name}} </label> </div> </div>
Typescript Code:
updateDetailsForm: FormGroup; private categories : Category[] = [] constructor(private router: Router, private ss : SearchService, private formBuilder: FormBuilder) { this.initForm() // before the categories loaded this.ss.getAllCategories().subscribe( data => { this.categories = data this.initForm() // refresh the form with categories } ) } initForm() { let allCategories: FormArray = new FormArray([]); for (let i = 0; i < this.categories.length; i++) { allCategories.push( new FormGroup({ 'name': new FormControl([this.categories[i].categoryName]) }) ) } this.updateDetailsForm = this.formBuilder.group({ 'image' : [''], 'categories': allCategories }) }
This is my user interface result, and I get the following error:
"inline template: 17:33 called: control.registerOnChange is not a function"

The number of checkboxes is correct, but the text is missing, and I canโt update the form result with the userโs choice.
What does the error mean?
How can I insert the correct text after this checkbox?
How to update user selection in form value?
source share