如何在日期选择器上查看月份 angular material

how to check the month on datepicker angular material

我有一个小的座位预订应用程序。进行预订后,彩色圆点将出现在 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 ;
  };
}