How to set minDate for ng-bootstrap datepicker
From your code snippet it looks like you are using ng-bootstrap from https://ng-bootstrap.github.io/#/components/datepicker. Assuming that I'm correct you need to use NgbDateStruct
(an object with fields like year
, month
, day
) instead of the built-in JavaScript Date
object. For example, to set a min date to the beginning of this year you would use:
this.minDate = {year: 2017, month: 1, day: 1};
Here is a working example in a plunker: http://plnkr.co/edit/VDEYDwp7QIZDDHatCNPh?p=preview
Just pass [minDate]="{year: 1980, month: 1, day: 1}"
:
<input type="text" [(ngModel)]="date" ngbDatepicker #d="ngbDatepicker" (focus)="d.open()" [minDate]="{year: 1980, month: 1, day: 1}" name="date" class="form-control"/>