Using reactive form validation with <input type=“file”> for an Angular app

前端 未结 3 1658
梦如初夏
梦如初夏 2020-12-30 03:46

I\'m writing a component with a file picker that uploads a file to our CDN. I\'m trying to add a reactive form on this component to validate the image input, so I can check

3条回答
  •  一向
    一向 (楼主)
    2020-12-30 04:17

    The value of is read-only, You need to set the option emitModelToViewChange:false when calling setValue() to avoid that 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.

    SOLUTION :

    this.form.get('').setValue(file, {emitModelToViewChange: false});
    

提交回复
热议问题