更改角度材料datePicker图标

时间:2017-07-18 12:33:31

标签: angular datepicker angular-material2

我想知道是否可以使用角度材料的datePicker更改显示的图标。

这是角材料文档中的代码。

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

有没有办法实现这个目标?

4 个答案:

答案 0 :(得分:15)

您可以在mat-datepicker-toggle

中添加mat-icon自定义
<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>

答案 1 :(得分:3)

您可以通过覆盖background类的mat-datepicker-toggle属性来完成此操作。从asset文件夹中添加所需图标的路径。

以下是使用calender中的alert.png图标替换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

答案 2 :(得分:1)

您可以在

内添加自己的图片
<mat-datepicker-toggle matSuffix (click)="openCalendar()">
    <mat-icon matDatepickerToggleIcon>
        <img src={{imageSource}}>
    </mat-icon>
</mat-datepicker-toggle>

答案 3 :(得分:0)

您可以像这样使用 svg 自定义图标:

<mat-form-field style="width: 100%; margin-top: 16px;">
    <mat-label style="font-size: 16px;">Date</mat-label>
    <input matInput [matDatepicker]="protocolIssueDate" formControlName="protocolIssueDate">
    <mat-datepicker-toggle matSuffix [for]="protocolIssueDate">
        <mat-icon matDatepickerToggleIcon>
            <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M7 4L9 4V6L15 6V4L17 4V6L20 6V14H18V8L6 8L6 18H14V20H4L4 6H7V4Z" fill="black" fill-opacity="0.38"/>
                <path d="M10 12V10H8V12H10Z" fill="black" fill-opacity="0.38"/>
                <path d="M14 10L12 10V12L14 12V10Z" fill="black" fill-opacity="0.38"/>
                <path d="M10 16V14L8 14V16L10 16Z" fill="black" fill-opacity="0.38"/>
            </svg>
        </mat-icon>
    </mat-datepicker-toggle>
    <mat-datepicker #protocolIssueDate startView="month" [startAt]="startProtocolIssueDate"></mat-datepicker>
</mat-form-field>