Search code examples
cssangularangular6angular-material-7

How to refresh mat-calendar after changing the background of highlighted dates


I have a mat-calendar control which is open always. On initial load, I am highlighting an array of dates which was able to do following this: Highlighting certain dates in mat-calendar. Now I have to highlight today's day (or selected date) on a button click. The highlighting works only when I change to different month, and then come back to the current month's view. Is there a way to refresh the mat-calendar dynamically? Please advise.

https://am-all-imports-zwnjbd.stackblitz.io


Solution

  • You can simply use MatCalendar.updateTodaysDate() to re-render it.

    @ViewChild(MatCalendar) calendar: MatCalendar<Date>;
    
    someEvent(){
        this.calendar.updateTodaysDate();
    }