我使用此验证规则:
this.addVisitorForm = this.fb.group({company: [null, []]});
如您所见,没有验证字段company
。但是Angular说这是无效的,该字段不必要吗?
HTML代码为:
<input maxlength="25" [ngClass]="{ 'has-error': addVisitorForm.get('company').invalid }"formControlName="company" type="text" class="form-control form-control-lg" required>
答案 0 :(得分:1)
您混合了HTML 5
验证和reactive form
验证。从required
标记中删除<input>
属性
<input maxlength="25" [ngClass]="{ 'has-error': addVisitorForm.get('company').invalid }"formControlName="company" type="text" class="form-control form-control-lg">