I'm using this Angular-2-datepicker. Everything works, however everytime I try to set the [(date)] attribute, it gives me the error.
date.getMonth is not a function
I've looked up some info and found out it could be because my variable is not of type date, however mine is, so I'm right now I'm stuck and cant find a solution.
My HTML:
...
<material-datepicker dateFormat="DD-MM-YYYY" weekStart="1" [(date)]="definitionDetails.From"></material-datepicker>
...
My Model:
export class ClosingDayDefinition implements Serializable<ClosingDayDefinition> {
ID: number;
DescriptionID: number;
Info: models.DefinitionDetailInfo;
Description: models.DefinitionDescription;
CodeId: number;
From: Date;
To: Date;
Recurring: boolean;
Holiday: boolean;
Groups: Array<models.ClosingDayGroup>;
TypeName: string;
My Component:
...
public definitionDetails: models.ClosingDayDefinition;
...
Var Log:
Seems like the From
property contains a string, and not a Date
object.
I'm guessing you're getting this date string from an API of some sort, try parsing it as a date instead of storing it straight away:
This will work
new Date('2017-03-08T00:00:00+01:00')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With