angularangular-materialangular-material-datetimepicker

Angular mat-date-range-input custom dateInput


I have created a demo here: https://stackblitz.com/edit/angular-ivy-8bvyfh?file=src/app/app.module.ts

I created mat-date-range-input, which works with MomentDateAdapter. When I select days from different months all fine: enter image description here

But if I select days from the same month, it's expected, that month will be omitted. So instead of: enter image description here

I would like to see: "24 - 27 October". How can I achieve it?


Solution

  • Demo in this Stackblitz Link

    One work around is you can replace text from input using template reference variable.

      <mat-date-range-input [rangePicker]="picker">
       <input
         #dateRangeStart
          matStartDate
          placeholder="Start date"
          (blur)="dateRangeChange(dateRangeStart, dateRangeEnd)"
          (dateChange)="dateRangeChange(dateRangeStart, dateRangeEnd)"
        />
        <input
          matEndDate
          placeholder="End date"
          #dateRangeEnd
          (dateChange)="dateRangeChange(dateRangeStart, dateRangeEnd)"
        />
      />
    

    and then inside component.ts file you can do like this

      dateRangeChange(s, e) {
        s.value = s.value.split(' ')[0];
      }