PrimeNG p-calendar 不适用于 Spring Boot Rest API

PrimeNG p-calendar not working with Spring Boot Rest API

此问题在开发者控制台或 Spring 后端没有错误。尝试使用 Reactive Form 和 patchValue.

编辑现有记录时,日期字段为空

日期输入代码:

<div class="p-field p-col">
    <label for="dueDate">Due Date</label>
    <p-calendar formControlName="dueDate" id="dueDate" showButtonBar="true" [showIcon]="true" placeholder="mm/dd/yyyy"></p-calendar>
</div>

编辑函数:

edit(id) {
    this._tasksService.getDetails(id).subscribe( x => {
        this.id = id;
        this.taskForm.patchValue(x);
        this.taskDialog = true;
    })
}

上面代码的问题是 p-calendar 需要一个 JS 日期。仅仅依靠patchValue是不够的。

要更正此问题,请更改编辑功能以添加 JS 日期类型。

edit(id) {
    this._tasksService.getDetails(id).subscribe( x => {
        this.id = id;
        x.dueDate = new Date(x.dueDate); 
        this.taskForm.patchValue(x);
        this.taskDialog = true;
    })
}