I have a dynamically generated Angular 2 FormGroup with multiple FormControl input fields. Some entries are Dates, which are retrieved from the server as unix timestamps.
What I would like to do:
- to be able to translate the unix timestamp into a human readable form when my FormGroup is populated, and also
- translate a person's date representation into a unix timestamp when the form is submitted.
Part 1 is somewhat simple using:
<input class="form-control" [formControlName]="question.key" [value]="this.form.controls[this.question.key].value | date:'dd/MM/yyyy'">
If this.form is a reference to FormGroup and this.question is a custom wrapper class based on the official guide to dynamic forms:
https://angular.io/docs/ts/latest/cookbook/dynamic-form.html
Trying to change the date input this way will not work, because the pipe will constantly try to convert the input value, thereby making the input unusable if you do not throw out the Invalid argument to exclude the 'DatePipe' for the pipe.
To clarify, I fill out my form using FormGroup.patchValue() api and FormGroup.getRawValue() form data using FormGroup.getRawValue() api.
I tried using the Angular 2 date picker, but they made my huge forms pretty slow, so I would like to do this without special date sorters or any jQuery dependent widgets.
Thanks in advance.
angular pipe forms datepicker
ktsangop
source share