Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change angular material datePicker icon

I wonder if it is possible to change the icon displayed using the datePicker of angular material.

This is the code from the angular material docs.

<md-input-container>
  <input mdInput [mdDatepicker]="picker" placeholder="Choose a date">
  <button mdSuffix [mdDatepickerToggle]="picker"></button>
</md-input-container>
<md-datepicker #picker></md-datepicker>

Is there a way to achieve that?

like image 828
edkeveked Avatar asked Jul 18 '17 12:07

edkeveked


People also ask

How do I change the calendar mat-icon?

Change the icon of mat-datepicker-toggle To change the icon of datepicker toggle button use mat-icon along with matDatepickerToggleIcon property inside mat-datepicker-toggle element.

How do I change the datepicker format in angular 6?

Create Custom Date Format Create a custom date format for parsing and displaying by Datepicker. export const MY_DATE_FORMATS = { parse: { dateInput: 'DD-MM-YYYY', }, display: { dateInput: 'MMM DD, YYYY', monthYearLabel: 'MMMM YYYY', dateA11yLabel: 'LL', monthYearA11yLabel: 'MMMM YYYY' }, };


2 Answers

You can add a mat-icon custom in mat-datepicker-toggle

<input matInput [matDatepicker]="dp" placeholder="Select minimum date" disabled>
<mat-datepicker-toggle matSuffix [for]="dp">
  <mat-icon matDatepickerToggleIcon>arrow_drop_down</mat-icon>
</mat-datepicker-toggle>
<mat-datepicker #dp disabled="false"></mat-datepicker>
like image 69
mathieu lavergne Avatar answered Oct 19 '22 08:10

mathieu lavergne


You can do it by overriding the background property of mat-datepicker-toggle class. Add the path of an icon that you want from your asset folder.

Here's an example of replacing calender icon with an alert.png icon in src > asset > img:

>>> .mat-datepicker-toggle {
    background: url("../../assets/img/alert-circle-24.png") no-repeat !important;
}

html:

<md-input-container align="end">
   <input mdInput [mdDatepicker]="datepicker"
                  [(ngModel)]="date">
   <button mdSuffix [mdDatepickerToggle]="datepicker"></button>
</md-input-container>

enter image description here

like image 36
Nehal Avatar answered Oct 19 '22 08:10

Nehal