【问题标题】:how to patch date onEdit in angular如何以角度修补日期onEdit
【发布时间】:2020-04-03 18:53:01
【问题描述】:

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

我已尝试给出格式。在数据库中,日期以 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 日期应该是补丁,在输入字段中我应该得到该特定记录的日期。

【问题讨论】:

    标签: angular angular-reactive-forms


    【解决方案1】:

    假设order@Input(),使用ngOnChanges 对来自输入的值做出反应:

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

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

    【讨论】:

      【解决方案2】:
      form.patchValue({Date: new Date().toLocaleString()});
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-04-12
        • 2017-10-16
        • 2021-03-12
        • 1970-01-01
        • 2018-07-09
        • 1970-01-01
        • 2018-05-01
        • 1970-01-01
        相关资源
        最近更新 更多