R
R
rinatoptimus2017-08-22 23:38:38
Angular
rinatoptimus, 2017-08-22 23:38:38

How to format date in Angular 2?

It is necessary that the date be displayed in the format DD/MM (the variant with the dot DD.MM is allowed). For example, "February 23" should look like this: 23/02 (or 23.02).
To do this, HTML has an editable input with a date:

<inline-editor type="date" [(ngModel)]="product.personBirthDate" (onSave)="saveEditable($event)" name="personBirthDate" size="8"></inline-editor>

In the main app.module.ts module it is written: Added in the component: Focused on this example from the official documentation In the console: joxi.ru/DmBLoJZhwywRJA How to format the date?
import { DatePipe } from '@angular/common';
personBirthDate: number = Date.now();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
denismaster, 2017-08-23
@denismaster

It should be divided [(ngModel)]into two blocks:

[ngModel] ="product.personBirthDate | date : "dd/MM/yyyy"
, which will display the data, and , to set it.
(ngModel) = "personBirthDate=$event"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question