angular - 如何通过pipe()->tap()添加一组模糊数据?
问题描述
这一切都是因为日期(Date)问题而开始的,为什么 Angular 向我显示数据库的日期少了一天。为了解决这个问题,我想到了这个:
客户端.component.ts
ClientesActualizado: cCliente[]; ----
this.clienteService.getClientes(page).pipe(
tap(response => {
/*the content is converted to a Client list */
(response.content as Cliente[]).forEach(cliente => {
//THIS TO PROVE THAT ALL NAMES SHOW
console.log(cliente.nombre);
//CHANGING the date, adding one more day
const createdAtCovert = moment(cliente.createAt).add(1, 'days');
this.date = createdAtCovert.format('YYYY-MM-DD');
//ADD IT BUT SEPARATELY, use the array for a single client, do not put them all at once.
this.ClientesActualizado = [({id: cliente.id, nombre:cliente.nombre, apellido: cliente.apellido,
email:cliente.email, createAt: this.date})];
console.log( this.ClientesActualizado)
});
})
我想用从点击(响应 => {})获得的模糊数据添加一个新数组,修改日期,然后在 HTML 中显示它。请希望你能帮助我,或者也许有另一种方法来纠正 Angular 显示日期少一天的错误。自从我驾驶 Spring 和 Angular 以来已经很短的时间了
解决方案
如果您希望日期在 HTML 中显示为 UTC,则可以使用带有 UTC 时区的 Angular Date 管道:
{{dateValue | date:'yyyy-MM-dd':'UTC'}}
否则,日期将在显示时转换为本地时间。
推荐阅读
- python - Django获取包含多对多关系pk的所有对象
- javascript - 在javascript中只运行一次函数
- javascript - Angular nativeElement offsetTop 总是 0
- wordpress - 如何导出 WooCommerce 订单
- javascript - 使用 javascript 函数时出现问题(对象未按预期显示)
- pyinstaller - 带有 fastapi 和数据库的 Pyinstaller
- c - 在什么情况下缓冲区已满
- angular - 如何以角度处理顺序间隔请求?
- javascript - 如何在 Django 中使用 Javascript 和经过身份验证的用户调用 Django API
- python - ValueError : 层序贯_13 的输入 0 与层不兼容: