Tymur Berezhnoi
Tymur Berezhnoi

Reputation: 706

HTML/Angular2 date picker disable to select a future date

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?

Upvotes: 1

Views: 8171

Answers (2)

mahesh
mahesh

Reputation: 21

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

<input matInput [max]="maxDate" [min]="minDate" [matDatepicker]="picker">

Upvotes: 2

Phil Cap
Phil Cap

Reputation: 209

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.

Upvotes: 1

Related Questions