【问题标题】:PrimeNG p-calendar not working with Spring Boot Rest APIPrimeNG p-calendar 不适用于 Spring Boot Rest API
【发布时间】:2021-02-09 10:20:16
【问题描述】:

这个问题在开发者控制台或 Spring 后端没有错误。尝试使用响应式表单和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;
    })
}

【问题讨论】:

    标签: angular spring-boot spring-mvc primeng


    【解决方案1】:

    上面代码的问题是p-calendar需要一个JS Date。仅仅依靠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;
        })
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-12
      • 2017-12-18
      • 1970-01-01
      • 2021-10-15
      • 2019-10-17
      相关资源
      最近更新 更多