[英]how to check the month on datepicker angular material
我有一个小型座位预订应用程序。 预约时,角料日历(日期选择器)中预约日期会出现一个彩色圆点。 问题是预订点显示在所有月份而不是预订月份,也就是说,如果我在 9 月 5 日预订,则在 10 月和 11 月以及 12 月等所有月份都可以看到该点那一年 。 我开发了这个代码来在日历中添加点,你能给我一个线索/帮助如何只在我预订的月份放置点吗? 非常感谢你,为我的无知感到抱歉,但我在这个领域真的很陌生
dateClass() {
return (date: Date): MatCalendarCellCssClasses => {
const arrDay = this.unavailableDates;
const arrDisp = this.reservDate;
let resp = 'tutte';
for (const il of arrDisp) {
if (date.getDate() === il.getDate()) {
resp = 'disponibiles';
return resp;
}
}
for (const el of arrDay) {
if (date.getDate() === el.getDate()) {
resp = 'non-disponibile';
return resp;
}
}
return resp;
};
}}
I think you want to compare the month and the year, rather the date.
dateClass() {
return (date: Date): MatCalendarCellCssClasses => {
let resp = 'tutte';
const unavailableDate = arrDay.some(d => d.getMonth() === date.getMonth() && d.getFullYear() === date.getFullYear());
const reserveDate = arrDisp.some(d => d.getMonth() === date.getMonth() && d.getFullYear() === date.getFullYear());
return unavailableDate ? 'disponibiles' : reserveDate ? : 'non-disponibile' : resp ;
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.