繁体   English   中英

我如何更改来自后端 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)})

我想更改日期的格式,但它给了我一个错误,说 ** result['birthDate']** is a String is not assignable to date,所以我将其更改为 ** result['birthDate']= new Date(test)** 但它返回一个无效的日期 注意:我正在使用 DatePicker。 任何帮助?

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM