How to validate field with input type=time via for

2019-08-29 04:46发布

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

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

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>

Simple FormGroup for above form

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

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.

2条回答
smile是对你的礼貌
2楼-- · 2019-08-29 05:05
<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>
查看更多
劳资没心,怎么记你
3楼-- · 2019-08-29 05:19

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>
查看更多
登录 后发表回答