【问题标题】:how to check the month on datepicker angular material如何检查日期选择器角度材料的月份
【发布时间】:2020-09-03 08:10:26
【问题描述】:

我有一个小型座位预订应用程序。进行预订时,角度材料日历(日期选择器)中的预订日期将出现一个彩色圆点。问题是预订点显示在所有月份而不是预订月份,也就是说,如果我在 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;
  };

}}

【问题讨论】:

  • getDate() 的 Date 对象返回“日期”,你想说getTime()吗?

标签: javascript angular typescript datepicker angular8


【解决方案1】:
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 ;
  };
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-13
    • 1970-01-01
    • 2020-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-12
    相关资源
    最近更新 更多