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?

3
  • First of all! Which datepicker are u using? Most of those datepicker fameworks contains implementations for date range selection Commented Jan 9, 2017 at 15:42
  • @Fals I'm using simple html input with type="datetime-local" Commented Jan 9, 2017 at 15:46
  • use mydatepicker it has these features Commented Jan 9, 2017 at 17:42

2 Answers 2

2

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

<input matInput [max]="maxDate" [min]="minDate" [matDatepicker]="picker">
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it seems now it's possible to use [max]="maxDate" [min]="minDate". Thanks
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.