1

在以反应形式修补值时,日期类型不显示值,因为datePipe 转换不适用于该字段。

组件.ts

  initX() {
    return this.fb.group({
      'date': [''],
      'nodes': this.fb.array([
        this.initY(),
        // this.initZ()
      ]),
    });
  }

for (let dayarray = 0; dayarray < plans.days.length; dayarray++) {
  const daysFormArray = this.form.get("days") as FormArray;
  daysFormArray.push(this.initX());
  this.form.patchValue({
    date: this.datePipe.transform(this.plan.days[dayarray].date, 'dd-MM-yyyy')
  });
}
this.form.patchValue(plans);

组件.html

<div formArrayName="days">
    <div *ngFor="let X of form['controls'].days['controls']; let ix=index">
        <div formGroupName="{{ix}}" class="days">
            <label [attr.for]="ix">Date: </label>
             <input type="date" formControlName="date">
        </div>
    </div>
</div>

我从服务器“日期”获得的输入日期:“2020-10-14T00:00:00.000+00:00”预计显示“14-10-2020”

4

0 回答 0