In Angular 4, How to Dynamically Set Min Date and Max Date in Date Picker

Set minDate/maxDate dynamically on html datepicker

Using moment here for date formation


Reference ---->

//Taken current date as min date. and random as max date. 
// Default format of date is as "YYYY-MM-DD" so we need to convert using moment

minDate = moment(new Date()).format('YYYY-MM-DD')
maxDate ="2018-09-08"


<input class="form-control" type="date" [min]="minDate" [max]="maxDate">

angularjs datepicker to set max date and min date dynamically

It seems that the element's configuration once initialized cannot be changed. Try putting the arrival input in ngIf, so that it is always rendered anew when departure changes.

Angular Material Datepicker min and max not working: Type 'Date' is not assignable to type 'number'

I found the culprit. The problem only occurs, when I import CustomFormsModule from 'ng2-validation' in my module.
As soon as I remove it, the correct min/max directives are used and no more errors are shown.

Related Topics

Leave a reply