简体   繁体   English

Angular2 Reactive表单 - 设置表单输入字段的默认值(输入类型=文件)?

[英]Angular2 Reactive forms - Set default value for form input field (input type=file)?

i have to set default image path into formbuilder but given exception. 我必须将默认图像路径设置为formbuilder但给出异常。 i have also try with empty string and null. 我也尝试使用空字符串和null。

 buildForm() {
        this.userForm = this.formBuilder.group({
            location_id: this.formBuilder.control(null),
            image: this.formBuilder.control('assets/images-demo/avatars/user.png'),
        });
    }

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. ERROR DOMException:无法在'HTMLInputElement'上设置'value'属性:此input元素接受一个文件名,该文件名只能以编程方式设置为空字符串。

Error says that it is not possible to set input programmatically for type='file' . 错误表示无法以编程方式为type='file'设置输入。

Only empty string is possible. 只有空字符串是可能的。

Many posts say that this is a security issue to change the input value for file type. 许多帖子都说这是更改file类型输入值的安全问题。

jQuery, Select Input FILE and also set it to another INPUT jQuery,选择输入文件并将其设置为另一个输入

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM