简体   繁体   English

Angular - 输入文件字段中的验证器

[英]Angular - Validator in an input file field

In angular, how can I make a obrigatory field validator for a field that will be inserted a file in?在 angular 中,如何为将插入文件的字段制作一个必填字段验证器? Validator.required is not working in this case. Validator.required 在这种情况下不起作用。

Html:网址:

<input class="input" type="text" formControlName="document" value="{{arquivosSelecionados[0] ? arquivosSelecionados[0][0].name : ''}}" disabled>
                
<app-form-messages class="md-inputfield"  [field]="formIncluirMembros.get('document')"></app-form-messages>

Typescript打字稿

this.formIncluirMembros.addControl("document", new FormControl(null, Validators.required));

Remove disabled in input rather use readonly if suit your requirement.如果适合您的要求,请在输入中删除disabled而不是使用readonly As adding it will exempt from validation checks as per documentation .添加后,它将根据文档免除验证检查。

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

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