I am trying to bind a DateTime column from a SQL Server database to an Angular Material DatePicker. Whenever the DatePicker loses focus, it highlights red like it is invalid. The data transfer gets/sets in both directions, but it gives the appearance of an error.
Basic function is that a C# API returns JSON data like { "endDate": "2019-01-16T00:00:00" }
. Angular consumes that and puts it into a model that's bound to the mat-form-field. The C# data type is DateTime
as is the SQL Server data type.
I think that my problem lies in the date format between SQL Server / C# / Angular
HTML
<mat-form-field appearance="outline" style="width:200px">
<mat-label>End Date</mat-label>
<input matInput [matDatepicker]="endPicker" placeholder="Choose a date" [(ngModel)]="trainClass.endDate" name="endDate">
<mat-datepicker-toggle matSuffix [for]="endPicker"></mat-datepicker-toggle>
<mat-datepicker #endPicker></mat-datepicker>
</mat-form-field>
Component:
trainClass: ITrainClass = {} as ITrainClass;
Interface:
export interface ITrainClass {
endDate: Date;
}
Any help would be appreciated!