如何通过表单控件验证输入类型为time的字段?二手角材料

时间:2019-02-02 21:05:12

标签: angular forms angular-material

输入类型为time的字段无法通过表单控件进行验证。 我收到错误消息:

  

错误错误:没有值访问用于与名称形式控制:“thirdCtrl”

部分代码无法通过Vaildator处理

 <mat-step [stepControl]="thirdFormGroup">
    <form [formGroup]="thirdFormGroup">    
<mat-form-field formControlName="thirdCtrl">
    <input matInput type="time">
    </mat-form-field>
      <button mat-button matStepperNext>Next</button>
    </form>
  </mat-step>

上述表单的简单FormGroup

this.thirdFormGroup = this._formBuilder.group({
      thirdCtrl: ['', Validators.required]
    });

我怀疑发生错误是因为FormControl尝试处理类型为time的输入字段,但我不知道如何针对我的情况更改此FormControl。

2 个答案:

答案 0 :(得分:2)

尝试将formControlName="thirdCtrl"绑定从<mat-form-field>移到<input>,例如:

<mat-step [stepControl]="thirdFormGroup">
    <form [formGroup]="thirdFormGroup">    
       <mat-form-field>
          <input matInput type="time" formControlName="thirdCtrl">
       </mat-form-field>
      <button mat-button matStepperNext>Next</button>
    </form>
</mat-step>

答案 1 :(得分:1)

<mat-step [stepControl]="thirdFormGroup">
    <form [formGroup]="thirdFormGroup">    
<mat-form-field>
    <input matInput type="time" formControlName="thirdCtrl">
    </mat-form-field>
      <button mat-button matStepperNext>Next</button>
    </form>
  </mat-step>
相关问题