问题
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?
回答1:
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>keyboard_arrow_down</mat-icon>
</mat-datepicker-toggle>
<mat-datepicker #dp disabled="false"></mat-datepicker>
回答2:
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>
来源:https://stackoverflow.com/questions/45166951/change-angular-material-datepicker-icon