Cuando intento agregar un valor inicial a un input type file desde un FormControl
me aparece el siguiente error:
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.
Este es el código de mi FormGroup
:
this.editProduct = new FormGroup({
'productImage' : new FormControl( '', Validators.required )
});
ngOnInit() {
this._productsService.getProduct( this.productId )
.subscribe( getProductData => {
this.editProduct.controls['productImage'].setValue(
this.product.productImage );
}
}
Form HTML:
<form class="animated fadeIn" [formGroup]="editProduct"
(ngSubmit)="updateProduct()" #form="ngForm">
<input class="form-control" type="file" [ngClass]="{ 'is-invalid' :
!editProduct.get( 'productImage' ).valid }" id="productImage"
formControlName="productImage">
<button class="btn btn-primary" type="submit"
[disabled]="!form.valid">Actualizar</button>
</form>