I have a date_of_birth field with an epoch string saved to it. I wanted to use angular material date picker to alter the date which is possible by converting it through
//convert matDatepicker timestamp format to epoch and save
var newDOB = new Date(privateUser.date_of_birth).getTime().toString();
privateUser.date_of_birth = newDOB;
before storing it into the db, however when trying to display it within the date selection as the default date, I'm not very sure how to revert it.
this is the current code i have
<div *ngIf="(userPrivate$ | async) as userPrivate">
<form (ngSubmit)="updateUser(user, userPrivate)">
<mat-form-field >
<input matInput type="text" [(ngModel)]="user.username" name="username" placeholder="Username">
</mat-form-field >
<mat-form-field >
<input matInput [matDatepicker]="dp" placeholder="Date of Birth" [(ngModel)]="userPrivate.date_of_birth" name="date_of_birth">
<mat-datepicker-toggle matSuffix [for]="dp"></mat-datepicker-toggle>
<mat-datepicker #dp >
</mat-datepicker>
</mat-form-field>
</form>
</div>
and when i try adding
<mat-form-field >
<input matInput [matDatepicker]="dp" placeholder="Date of Birth" [formControl]="userPrivate.date_of_birth" [(ngModel)]="userPrivate.date_of_birth" name="date_of_birth">
<mat-datepicker-toggle matSuffix [for]="dp"></mat-datepicker-toggle>
<mat-datepicker #dp >
</mat-datepicker>
</mat-form-field>
I will get an error as it will not be able to read the value, it also cant take in whatever it was I was trying to do by adding the function to convert it from epoch.
<mat-form-field >
<input matInput [matDatepicker]="dp" placeholder="Date of Birth" [formControl]="getDate(userPrivate.date_of_birth)" [(ngModel)]="userPrivate.date_of_birth" name="date_of_birth">
<mat-datepicker-toggle matSuffix [for]="dp"></mat-datepicker-toggle>
<mat-datepicker #dp >
</mat-datepicker>
</mat-form-field>
where getDate(date)
function
getDate(date){
// convert Epoch time to timestamp format
var newDate= new Date(date).getTime();
return newDate;
}
How am I suppose to be approaching this so that I can have my date input to display the date_of_birth value as a default?