change angular material datePicker icon

核能气质少年 提交于 2019-12-10 16:56:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!