Angular-material:-更改手风琴中垫扩展面板的默认图标

时间:2018-12-28 15:16:24

标签: angular angular-material

下面是Stackblitz的链接,我试图用图像/其他图标更改图标(箭头)。我尝试使用加号箭头而不是向下箭头。

https://stackblitz.com/edit/angular-wwpb6y?file=styles.css

1 个答案:

答案 0 :(得分:2)

为扩展面板提供参考ID example,并将hideToggle属性设置为true。 将图标放在<mat-panel-description>中,然后使用面板的expanded属性显示或隐藏相关图标。

 <mat-expansion-panel  class="custom-header" hideToggle="true" #example>
    <mat-expansion-panel-header>
      <mat-panel-title>
        Collapsible Group Item #1
      </mat-panel-title>
      <mat-panel-description> 
        <mat-icon *ngIf="!example.expanded">add</mat-icon>
        <mat-icon *ngIf="example.expanded">add_box</mat-icon>
      </mat-panel-description>
    </mat-expansion-panel-header>

     <p>
      Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
    </p>
  </mat-expansion-panel>

CSS:

.custom-header .mat-expansion-panel-header-title, 
.custom-header .mat-expansion-panel-header-description {
  flex-basis: 0;
}

.custom-header .mat-expansion-panel-header-description {
  justify-content: space-between;
  align-items: center;
}

也请检查链接:

https://stackblitz.com/edit/angular-irnxvd?file=src%2Fapp%2Fapp.component.css