I am working on angular application and I have successfully retrieved data from database and trying to set values of form control using patch Value method but unfortunately I am getting error i.e
core.js:6185 ERROR DOMException: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.
Below is my code Snippet
component.ts
ngOnInit(): void {
this.EditForm();
this.GetValues() //method where I am retreiving data from firebase and iside it I am calling set Value
}
EditForm() {
this.exampleForm = this.fb.group({
imgurl: ['',Validators.required],
title: ['', Validators.required],
desc: ['', Validators.required],
category: [this.selected, Validators.required],
subcategory: [' ', Validators.required],
name: ['', Validators.required],
privacy: ["true"],
});
}
setFormValue(d4) {
this.imageSrc=d4.imgurl // this I have done to use string interpolation in template
this.exampleForm.patchValue({
imgurl:this.imageSrc,
title:d4.title,
desc:d4.desc,
category:d4.category,
name:d4.name,
privacy:d4.privacy
})
}
component.html
<div class="col-md-8 col-sm-9 col-xs-9">
<form class="create-form" [formGroup]="exampleForm" novalidate (ngSubmit)="onSubmit(exampleForm.value)">
<div class="col-md-4 col-sm-3 col-xs-12">
<input type="file" multiple (change)="detectFiles($event) "
accept="image/x-png,image/gif,image/jpeg"
class="form-control"
formControlName="imgurl">
<img id="imgid"
height="200" width="200"
class="img-rounded"
[src]="imageSrc || 'http://placehold.it/180'" alt="your image" />
</div>
//rest of form controls
But when I see my submit button is disabled even though all form controls having value.When I inspect in inspector I found img controller is having ng-invalid. What could be the reason I am not sure.Please help me here