简体   繁体   English

如何使用日期选择器作为表单的输入 - angular

[英]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.

相关问题 Angular 2中日期选择器如何使用? - How to use date picker in Angular 2? 角度6:如何将日历/日期选择器与表单交互? - Angular 6: How to Intergarte calender/date picker with form? 如何在材料日期选择器中使用 Angular 日期 Pipe ? - How Do I use Angular Date Pipe in material date picker? 如何使用my-date-picker在Angular中使用Date属性 - How to use Date property with Angular using my-date-picker 如何在不显示输入字段的情况下显示 angular 日期选择器 - How to show angular date picker without showing the input field Angular 如何为日期选择器上的输入分配空值 - Angular How Can I Assign Null Value to Input on Date Picker 如何在Angular中设置角度日期选择器日期格式以作为一种服务方法? - How can I set angular date picker date-format form a method of service in Angular? Angular 反应形式材料 日期选择器手动输入格式 DD/MM/YYYY - Angular reactive Form material Date picker manual input format DD/MM/YYYY Angular 材料日期选择器发送日期前 1 天以及如何使用 Angular 材料日期选择器的时刻 - Angular material date picker sending date 1 day before and how to use moment with Angular material datepicker 如何正确使用 <input type=“date”> 在角? - How to correctly use <input type=“date”> in Angular?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM