I'm creating a simple Reactive form in Angular. There is already this question and is marked duplicate.
But mine is different. In my case I've a custom component on which I want to use formControlName
.
Though the form is working correctly but there is an error on console. Please tell me how to fix this.
HTML
<form [formGroup]="myReactiveform" (ngSubmit)="submitForm()">
<my-file-uploader
formControlName="attatchmentControl">
</my-file-uploader>
<button type="submit">Submit</button>
</form>
TS
myReactiveform: FormGroup;
ngOnInit(): void {
this.myReactiveform= new FormGroup({
attatchmentControl: new FormControl('', [])
});
submitForm() {
...
}
}
my-file-uploader.component.html
<input type="file" single>
Error
ERROR Error: No value accessor for form control with name: 'attatchmentControl' at _throwError (forms.js:2574:1) at setUpControl (forms.js:2394:1) at FormGroupDirective.addControl (forms.js:5626:1) at FormControlName._setUpControl (forms.js:6177:1) at FormControlName.ngOnChanges (forms.js:6122:1) at FormControlName.rememberChangeHistoryAndInvokeOnChangesHook (core.js:1471:1) at callHook (core.js:2490:1) at callHooks (core.js:2457:1) at executeInitAndCheckHooks (core.js:2408:1) at selectIndexInternal (core.js:8194:1)