When I use an input type date in Angular 4 with two Date picker fields, the issue arises when I select a range of dates and press save. Instead of saving the selected dates, it is saving the current date. I have tried using ngModelChange to update the value, but it still saves as the current date in the database. Below is the code snippet:
<app-input-field orientation="top" label="Beginning Date">
<input [min]="today" type="date" step="1" [(ngModel)]="newCreate" style="width:250px">
</app-input-field>
<br>
<app-input-field orientation="top" label="Ending Date">
<input [min]="today" type="date" step="1" [(ngModel)]="newEnd" style="width: 250px;">
</app-input-field>
Below is the TypeScript file:
newCreate: string = new Date().toISOString().substring(0, 19);
newEnd: string = new Date().toISOString().substring(0, 19);
And here is the save function:
save() {
// How can I convert this date properly before saving it? It currently
// saves with minutes and other details.
this.newProject.name = this.newProjectName;
this.newProject.state = this.newState;
this.newProject.type = this.newType;
this.newProject.created = new Date(this.newCreate);
this.newProject.ending = new Date(this.newEnd);
this.newProject.category = this.category;
this.newProject.subProjectIds = this.subProjectIds;
this.store.dispatch(new UpsertProjectAction(this.newProject));
this.dialogRef.close(this.newProject);