0

I am using Angular 5 and with that, Angular Material. I have a datepicker that when opened, defaults to picking a month. However, it still requires you to select a day after you select a month, and displays the date selected including the day. Is there a way to make it so the user only needs to select a month and year? At the very least can I format the displayed selected date to only show the month and year? Here is the code for the datepicker:

<mat-form-field>
    <input matInput [matDatepicker]="departMonthPicker" [max]="today" placeholder="Report Month" [formControl]="departStart">
    <mat-datepicker-toggle matSuffix [for]="departMonthPicker"></mat-datepicker-toggle>
    <mat-datepicker #departMonthPicker startView="year" [startAt]="yearStart"></mat-datepicker>
</mat-form-field>

I have tried looking for solutions to this, but either other solutions are just trying to figure out how to add the ability to select the year/month at all, or they are for older versions of angular and angular material.

DeceitfulEcho
  • 71
  • 4
  • 14
  • 1
    Refer to the material documentation: [Watching the views for changes on selected years and months](https://material.angular.io/components/datepicker/overview#watching-the-views-for-changes-on-selected-years-and-months) (the code block is labeled `Datepicker emulating a Year and month picker`). I am not sure if it is backward compatible with angular5 or if you must upgrade to 6 for this feature. – Igor Aug 20 '18 at 20:17
  • @Igor After some research I have determined that is only in angular material 6, the events for selecting a month/year don't appear to be in angular material 5. – DeceitfulEcho Aug 20 '18 at 21:31

0 Answers0