I am using Angular 8 with Asp.Net Core. The current problem I'm having is that I can not display the dates within a Modal using [(ngModel)] and a date pipe.
What I would like to do is to convert the Asp.Net Core DateTime into an Angular Date format in the constructor.
Here is my code. Created, StartDate and EndDate are all Date.
export class Content {
Id: string;
CompanyId: string;
Created: Date;
Name: string;
Url: string;
Instructions: string;
Tags: string;
StartDate: Date;
EndDate: Date;
Deleted: Boolean;
Pause: Boolean;
Published: Boolean;
constructor(contentResponse: any) {
this.Id = contentResponse.id;
this.CompanyId = contentResponse.companyId;
this.Created = contentResponse.Created;
this.Name = contentResponse.name;
this.Url = contentResponse.url;
this.Instructions = contentResponse.instructions;
this.Tags = contentResponse.tags;
this.StartDate = contentResponse.startDate;
this.EndDate = contentResponse.endDate;
this.Deleted = contentResponse.deleted;
this.Pause = contentResponse.pause;
this.Published = contentResponse.published;
}
}
From console.log, I can see the following Date formats.
JSON from API
created: "2019-08-03T21:26:51.7981863"
endDate: "2020-12-31T00:00:00"
startDate: "2019-07-15T00:00:00"
After conversion using current constructor
Created: undefined
EndDate: "2020-12-31T00:00:00"
StartDate: "2019-07-15T00:00:00"
Does anyone know how to convert this in the constructor so Angular can display this information and work with it?
Any help is much appreciated. Thanks!