我如何更改来自后端 Angular REST API 的格式?

How i can change the format coming from backend Angular REST API?

我正在使用以下代码:

this.elService.getOne(id)
  .subscribe((result: ModelName) => {
 let test = this.datePipe.transform(result['birthDate'], 'mm/dd/yyyy')
  result['birthDate']= test
  console.log(result['birthDate'])
  this.parentForm.patchValue(result)})

我想更改日期的格式,但它给我一个错误,指出**结果['birthDate']**是一个不可分配给日期的字符串,所以我将其更改为**结果['birthDate']= new Date(test)** 但它 returns 是一个无效日期 注意:我正在使用 DatePicker。 有帮助吗?

无需使用额外的测试变量,您可以直接将更新日期分配给结果['birthDate']

result['birthDate'] = this.datePipe.transform(new Date(result['birthDate']), 'mm/dd/yyyy')