【问题标题】:How to apply date pipe on an input field which is a part of a formGroup如何在属于 formGroup 的输入字段上应用日期管道
【发布时间】:2022-12-20 08:33:14
【问题描述】:

我正在使用 Angular 14。我已经看到很多关于我的问题的答案,但我的要求略有不同。这是我的 HTML:

<input type="text" pInputText formControlName="startDate">

来自后端的值为“2022-12-01T00:00:00.000+00:00”。 我被告知不要创建任何自定义管道,只需在模板本身上使用一些内置日期管道并将输入字段值转换为月/日/年格式。不触及 formGroup 代码是否可能?

【问题讨论】:

    标签: angular


    【解决方案1】:

    Angular 具有用于格式化日期的内置管道。管道可以应用如下:

    {{ myDate | date: 'MM/dd/yy'}}
    

    其中 myDate 是存储日期的 Typescript/Javascript 变量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-26
      • 1970-01-01
      • 2019-07-11
      • 1970-01-01
      • 2022-01-06
      • 2022-01-11
      • 2015-01-17
      • 1970-01-01
      相关资源
      最近更新 更多