I am using the ng2-datepicker in my angular app and I want to update the date from the typescript file.
In the html template:
<ng2-datepicker [options]="optionsForMenuDate" [(ngModel)]="selectedDate" name="selectedDate"></ng2-datepicker>
It is binding to a moment object, so I am trying to update it like this (I have included moment in the angular solution):
this.selectedDate = this.moment(date);
Where date it the js Date object that I want to set the date to. This just sets the component to null though, even this this.selectedDate is not null.
console.log(this.selectedDate); // logs a moment object
Any ideas on how to achieve this?
I was having the same issue and I got it working by following way.
The problem with your code is at below line,
Here, property 'selectedDate' should be of type 'DateModel' and not the moment object. The DateModel is defined at,
And it has a following properties,
Now you need to set momentObj and formatted properties to get it working.
Here is the sample code,