I would like to limit the input number that can go up to the current year, the user cannot enter a year higher than the current one. How can I do it?
My code:
<ion-item>
<ion-label>Year</ion-label>
<ion-input [(ngModel)]="season.Year" type="number" ></ion-input>
</ion-item>
使用常规的HTML输入属性,例如min
和max
:
<ion-input [(ngModel)]="season.Year" type="number" min="1" max="5"></ion-input>
You can use min
property for these. Since you are using a number
type, just add min
attribute:
<ion-input [(ngModel)]="season.Year" type="number" min="2018"></ion-input>
Examples:
Enter a date before 1980-01-01:
<input type="date" name="bday" max="1979-12-31">
Enter a date after 2000-01-01:
<input type="date" name="bday" min="2000-01-02">
Quantity (between 1 and 5):
<input type="number" name="quantity" min="1" max="5">
You can do something like this if you want to hard core the max value.
<ion-input [(ngModel)]="season.Year" type="number" min="19XX" max="2018"></ion-input>
If you dont want to hard core the current year you can use Date class or use moment.js to fetch the current year and bind the year in html as follows.
<ion-input [(ngModel)]="season.Year" type="number" min="19XX" max="{{maxyear}}"></ion-input>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.