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

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

问题描述

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

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'

部分代码无法通过Vaildator处理

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>

上述表单的简单FormGroup

Simple FormGroup for above form

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"绑定从<mat-form-field>移到<input>,例如:

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>

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

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