How to set minDate for ng-bootstrap datepicker
Below is the code I am using to set minDate
<input ngbDatepicker #d="ngbDatepicker" [minDate]="minDate" [formControl]="Form.controls['dateOfBirth']">
In the component, I am setting the minDate as shown below:
public minDate: Date = void 0;
constructor() {
this.minDate = new Date(1950, 1, 1);
}
But the datepicker still shows 2007 as minDate. There is something missing. Let me know if any other information is required.
Thank you for your time.
source to share
From your code snippet, it looks like you are using ng-bootstrap from https://ng-bootstrap.github.io/#/components/datepicker . Assuming I'm right, you need to use NgbDateStruct
(with object fields, such as year
, month
, day
) instead of the built-in JavaScript object Date
. For example, to set a minimum date at the beginning of this year, you would use:
this.minDate = {year: 2017, month: 1, day: 1};
Here's an example of working in plunker: http://plnkr.co/edit/VDEYDwp7QIZDDHatCNPh?p=preview
source to share