3

I am using Angular material calendar (i.e) mat-calendar. I am trying to highlight some of the dates in the calendar. But I couldn't see any documentation on that. Can anyone help me on that.

HTML

<mat-card>
<mat-calendar name="appoinment_date" [selected]="selectedDate (selectedChange)="onSelect($event)"></mat-calendar>
</mat-card>

TS

  onSelect(event){
    this.selectedDate= event;
  }

What I am Getting //Can only select dates My output

What I want is // Should able to highlight dates

enter image description here

Chris
  • 1,236
  • 2
  • 18
  • 34

2 Answers2

1

Its 2019. for anyone still looking for an answer

<mat-calendar  [dateClass]="dateClass()" 
(selectedChange)="getDayRequestsList($event)"> </mat-calendar>


dateClass() {    
return (date: Date): MatCalendarCellCssClasses => {
  const highlightDate = this.datesToMark // array of dates
    .map(strDate => new Date(strDate)) // wrap with new Date if not in 
    date object
    .some(d => d.getDate() === date.getDate() && d.getMonth() === 
    date.getMonth() && d.getFullYear() === date.getFullYear());
  console.log(highlightDate);

  const highlightCurrentDate = this.upcomingCalendarEvents
  .map(strDate => new Date(+strDate.date))
  .some(d => d.getDate() === date.getDate() && currentDate.getDate() === 
    d.getDate() && d.getMonth() === date.getMonth() && d.getFullYear() === 
date.getFullYear());
console.log(highlightDate);
  if(highlightCurrentDate) {
    return 'highlight-current-date-class'
  } else if(highlightDate) {
    return 'highlight-date-class'
  } else {
    return ''
  }


};

}
PowerStat
  • 3,757
  • 8
  • 32
  • 57
0

Event calendar in Angular Material Design

I think this is what you wanted. You can highlight date but Not possible to show events. I am also looking for alternatives.

user12
  • 197
  • 2
  • 11