[英]How to use a date picker as an input in a form - angular
I have a form with some mat-form-field, it is supposed to have together with others two inputs as date picker我有一个带有一些 mat-form-field 的表单,它应该与其他两个输入一起作为日期选择器
this.templateForm = this._formBuilder.group({
arrivalDate: new FormControl('', Validators.required),
executionDate: new FormControl('', Validators.required),
unit: new FormControl(),
user: new FormControl(),
})
my html is something like that我的 html 就是这样的
<form name="templateForm" [formGroup]="templateForm">
<mat-form-field formControlName="arrivalDate">
<app-date-picker></app-date-picker>
</mat-form-field>
<mat-form-field formControlName="executionDate">
<app-date-picker></app-date-picker>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label> Unit</mat-label>
<mat-select formControlName="unit">
<mat-option *ngFor="let unit of units" [value]="unit">{{ unit.name }}</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label> Users</mat-label>
<mat-select formControlName="user" multiple
(selectionChange)="changeSelectedUsers($event.value)">
<mat-option *ngFor="let user of usersSub$ | async; let id = index" [value]="user">{{
user.givenName }}</mat-option>
</mat-select>
</mat-form-field>
</form>
I'm getting this error我收到这个错误
ERROR Error: mat-form-field must contain a MatFormFieldControl.
My question is how to use a customized date picker component inside a form?我的问题是如何在表单中使用自定义日期选择器组件?
It seems like the "formControlName" is not in the correct place but I still don't see where should I put it似乎“formControlName”不在正确的位置,但我仍然看不到我应该把它放在哪里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.