代码之家  ›  专栏  ›  技术社区  ›  POV

如何不需要输入?

  •  -1
  • POV  · 技术社区  · 6 年前

    我使用此验证规则:

     this.addVisitorForm = this.fb.group({company: [null, []]});
    

    如您所见,字段没有验证 company . 但是角说它是无效的,怎么做这个场就没有必要了?

    HTML代码是:

    <input maxlength="25" [ngClass]="{ 'has-error': addVisitorForm.get('company').invalid }"formControlName="company" type="text" class="form-control form-control-lg" required>
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   profanis    6 年前

    你把 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">
    
    
    推荐文章