简体   繁体   English

在 Angular 8+ 中禁用未来日期

[英]Disable future dates in Angular 8+

<input type="date" class="form-control date-picker" id="date2" name="date" data-date-format="DD MMMM YYYY" [min]="" ngModel required placeholder="DOB">

I am trying to fade out future dates without a library in Angular.我试图在 Angular 中没有库的情况下淡出未来的日期。

Try using:尝试使用:

 const datepicker = document.getElementById('date'); const today = new Date(); let date = today.getDate() > 9? today.getDate(): `0${today.getDate()}`; let month = today.getMonth() > 9? today.getMonth() + 1: `0${today.getMonth() + 1}`; let year = today.getFullYear(); datepicker.setAttribute('max', `${year}-${month}-${date}`); console.log(datepicker);
 <input type="date" id="date" name="bday">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM