1
votes

Is it possible to customize angular2+ material datepicker's date view like below?

enter image description here

The main libs and version:

angular: 5.2.9
@angular/material: 5.2.4
1
have you played with css? - Pardeep Jain
@PardeepJain, I tried, but the problem is I can't add dynamic classes to the different type of date - Chen Dachao
Oh, probably then you can't - Pardeep Jain

1 Answers

0
votes

Fortunately, I figure out how to resolve it finally.

Coz I'm using angular5, so one possible solution is like this, see below snippet:

setTimeout(()=>{
      let elements = document.querySelectorAll('.tracker');
      let x =  elements[0].querySelectorAll('.mat-calendar-body-cell');
      x.forEach(y => {
        let c = new Date(y.getAttribute("aria-label"));
        if(c < this.startDate){
          const cellContent = y.querySelector('.mat-calendar-body-cell-content');
          cellContent.classList.add('custom-calendar-cell');
        }
      });
    });

For angular6+, you can refer to this sample.