3

在一种形式中,我使用了角度材料日期选择器。OnEdit 我想用表单日期修补日期,但它显示为空,但日期即将出现在表单页面上。为了我根据 id send onEdit 从数据库中获取记录。

我试图给出格式。在数据库中,日期以 18.4.2019 格式存储。

form.patchValue({Date: order.Date});
<mat-form-field>
  <input matInput [matDatepicker]="picker"formControlName="dDate" id="Date" readonly (click)="picker.open()"><mat-datepicker-toggle matSuffix [for]="picker"><mat-icon matDatepickerToggleIcon>date_range</mat-icon></mat-datepicker-toggle>
  <mat-datepicker #picker></mat-datepicker>
</mat-form-field>

onEdit日期应该是补丁,在输入字段中我应该得到该特定记录的日期。

4

2 回答 2

0

假设order@Input(), 用于ngOnChanges对输入值做出反应:

ngOnChanges(changes: SimpleChanges) {
  if (changes.order && changes.order.currentValue) {
    this.form.patchValue({dDate: this.order.Date});
  }
}

在您的标记中formControlName,“ dDate”与您的打字稿不同,但它们应该匹配。

于 2019-04-18T16:43:38.733 回答
-1
form.patchValue({Date: new Date().toLocaleString()});
于 2019-04-18T17:39:24.827 回答