如何通过表单控件验证输入类型=时间的字段?使用的角材料 [英] How to validate field with input type=time via form control? Used Angular Material

查看:19
本文介绍了如何通过表单控件验证输入类型=时间的字段?使用的角材料的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入类型=时间的字段无法通过表单控件进行验证.我收到错误:

Field with input type=time can't validate via form control. I get error:

错误错误:没有名称的表单控件的值访问器:'thirdCtrl'

ERROR Error: No value accessor for form control with name: 'thirdCtrl'

部分代码,不通过 Validator 处理

Part of code, which don't handle via 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>

上述表单的简单表单组

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

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

I suspect error occurs because FormControl try to handle input field with type time, but I don't know how to change this FormControl for my case.

推荐答案

尝试将 formControlName="thirdCtrl" 绑定从 移动到,如:

Try to move formControlName="thirdCtrl" binding from <mat-form-field> to <input>, like:

<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>

这篇关于如何通过表单控件验证输入类型=时间的字段?使用的角材料的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆