本文介紹了Angular 2 Ionic 2 - 如何將最大或最小日期設(shè)置為今天以進行日期輸入?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
<input class="alert-input date-input" #dob="ngModel" name="dob" max="2018-03-07" [(ngModel)]="leadDetail.dob" type="date"></div>
How can I set the max date for today instead of 2018-03-07 dynamically?
I tried following methods-
<input max="today" type="date"></div>
<input max="{{today | date:'yyyy-mm-dd'}}" type="date"></div>
Class -
public today = new Date();
but no luck.
解決方案
Try this:
<input class="alert-input date-input" name="dob" [max]="today" type="date">
today = new Date().toJSON().split('T')[0];
Working Example Demo
Reason:
Because when you are using new Date()
this will give you full date with time zone and time etc, you have to assign only Date so you have to split this with only Date.
For more clarification run this:
console.log(new Date(), '----', new Date().toJSON());
這篇關(guān)于Angular 2 Ionic 2 - 如何將最大或最小日期設(shè)置為今天以進行日期輸入?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!