how to add a secondary action in mat-list-option (mat-selection-list) item

一曲冷凌霜 提交于 2019-12-12 21:02:24

问题


How is it possible, to add an secondary action (mat-icon-button) in an mat-selection-list inside the mat-list-option element.

Currently all items are added inside the mat-list-text div.

example (https://stackblitz.com/edit/angular-dwac7y):

<mat-selection-list [(ngModel)]="selectedOptions">
    <mat-list-option *ngFor="let item of items;" [value]="item.id" [disableRipple]="true">
        <mat-icon matListAvatar>person</mat-icon>

        <h3 matLine> {{item.name}}</h3>
        <p matLine>
            {{item.details}}
        </p>

        <button mat-icon-button (click)="onEdit($event, item)">
            <mat-icon>edit</mat-icon>
        </button>
    </mat-list-option>
</mat-selection-list>

回答1:


you could do it as following.

<h2>Selection-List with secondary action:</h2>

<mat-selection-list [(ngModel)]="selectedOptions">
  <mat-list-option *ngFor="let item of items;" [value]="item.id" [disableRipple]="true">
    <div style="display:flex; justify-content:space-between;align-items:center">
      <div style="display:flex;align-items:center">
        <mat-icon matListAvatar>person</mat-icon>

        <div style="display:flex; flex-direction:column">
          <div>
            <h3 matLine> {{item.name}}</h3>
          </div>
          <div style="margin-top:-30px">
            <p matLine>
              {{item.details}}
            </p>
          </div>
        </div>
      </div>
      <div>
        <button mat-icon-button (click)="onEdit($event, item)">
          <mat-icon>edit</mat-icon>
        </button>
      </div>
    </div>
  </mat-list-option>
</mat-selection-list>

but the following style...

<div style="margin-top:-30px">

is not a good solution imo.



来源:https://stackoverflow.com/questions/53815547/how-to-add-a-secondary-action-in-mat-list-option-mat-selection-list-item

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