首页 > 解决方案 > 如何通过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 以来已经很短的时间了

标签: angularspringdate

解决方案


如果您希望日期在 HTML 中显示为 UTC,则可以使用带有 UTC 时区的 Angular Date 管道: {{dateValue | date:'yyyy-MM-dd':'UTC'}} 否则,日期将在显示时转换为本地时间。


推荐阅读