1

I have an issue related to html/angular 2 date picker. So i have such input tag:

<input #createdAt ngModel type="datetime-local" id="createdAt" name="date" class="form-control" required>

but i don't want allow to a user select future date, so only today and past date is allowed. How can i achieve such behaviour with angular 2?

Tymur Berezhnoi
  • 706
  • 1
  • 14
  • 27

2 Answers2

2

Below is the syntax for max/min attributes for the angular material date picker.

<input matInput [max]="maxDate" [min]="minDate" [matDatepicker]="picker">
mahesh
  • 21
  • 5
1

One of the option is to leverage the max attribute of <input type="datetime-local such as: <input type="date" name="bday" max="1979-12-31">

An alternative is to use an existing Angular2 component, such as the date picker from Bootstrap Angular 2. The component is highly customizable and your goal can be achieved by setting the maxDate input.

Code Spark
  • 178
  • 14
Phil Cap
  • 209
  • 2
  • 10