I'm using angular reactive forms, the form group is initialized in the parent component and form controls are located in the child components.
The problem is that I getting the following error message when I access the page:
ERROR Error: No value accessor for form control with unspecified name attribute
For testing purpose, I tried to replace mat-slide-toggle with input checkbox and the error goes away, why is it complaining with slider, I can't understand.
Here's similar example:
Parent Module
@NgModule({
...
declarations: [ParentComponent],
imports: [
...,
MatSlideToggleModule,
]
})
export class ParentModule {}
Parent Component
@Component({
selector: 'app-parent',
template: `
<form [formGroup]="myFormGroup">
<app-child-a [subscribedControl]="$any(myFormGroup.controls.myOption)"></app-child-a>
</form>
`
})
export class ParentComponent {
public myFormGroup: FormGroup = this._fb.group({
myOption: [true, [Validators.required]],
});
constructor(private _fb: FormBuilder) {}
}
Child A Component
@Component({
selector: 'app-child-a',
template: `
<mat-slide-toggle [formControl]="subscribedControl"></mat-slide-toggle>
`
})
export class ChildAComponent {
@Input() public subscribedControl!: FormControl;
}
Any ideas?