Angular Material 2 DatePicker with only month and year

20,797

Solution 1

For this time this is an open bug. See this link

Solution 2

it will helpful material datepicker with month and year format.check link for MM-YYYY

Share:
20,797
Admin
Author by

Admin

Updated on February 23, 2021

Comments

  • Admin
    Admin about 3 years

    I was looking for a way to make the angular material datepicker 2 change to only year and month mode but it does not have that option in the documentation

    I can set the startView but when month or year is selected, change to Day mode

    <md-form-field>
         <input mdInput [mdDatepicker]="picker" placeholder="Choose a date">
         <md-datepicker-toggle mdSuffix [for]="picker"></md-datepicker-toggle>
         <md-datepicker #picker startView="year" [startAt]="startDate"></md-datepicker>
    </md-form-field>
    

    I want this: https://plnkr.co/edit/eV2Kmt?p=preview

    But that plunker is in angular material 1

    Any help? :)

  • Edric
    Edric over 6 years
    Looks like there's a new PR which appears to have support for year selection, although it also appears that it won't be released until possibly 5.1 (as indicated by the milestone): github.com/angular/material2/pull/8565
  • Walfrat
    Walfrat almost 5 years
    This works but not at 100%, you can still access to the day by clicking in the top left field.
  • Ben Petersen
    Ben Petersen almost 3 years
    At least give credit... this is just the Angular Material example material.angular.io/components/datepicker/…