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?
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.
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' }, };
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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With