Angular 将数据从动态mat单元传递到单击功能

Angular 将数据从动态mat单元传递到单击功能,angular,angular-material,Angular,Angular Material,我有一个mat表,用于显示从服务接收的数据。此表中的一列显示存储在表中显示的对象中的属性名称 我的桌子看起来像这样 <table class="session-table" mat-table [dataSource]="sessions"> <ng-container matColumnDef="name"> <mat-header-cell *matHeaderCellDef>Name</mat-header-cell&

我有一个mat表,用于显示从服务接收的数据。此表中的一列显示存储在表中显示的对象中的属性
名称

我的桌子看起来像这样

<table class="session-table" mat-table [dataSource]="sessions">

      <ng-container matColumnDef="name">
        <mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
        <mat-cell *matCellDef="let element">{{element.sessionName}}</mat-cell>
      </ng-container>

      <ng-container matColumnDef="date">
        <mat-header-cell *matHeaderCellDef>Date</mat-header-cell>
        <mat-cell *matCellDef="let element">{{element.sessionDate}}</mat-cell>
      </ng-container>

      <ng-container matColumnDef="link">
        <mat-header-cell *matHeaderCellDef>Link</mat-header-cell>
        <mat-cell *matCellDef="let element">{{element.sessionLink}}</mat-cell>
      </ng-container>

      <ng-container matColumnDef="delete">
        <mat-header-cell *matHeaderCellDef>Control</mat-header-cell>
        <mat-cell *matCellDef="let row">
          <button mat-icon-button (click)="showDeleteModal()"><mat-icon><fa name="trash" size="lg"></fa></mat-icon></button>
        </mat-cell>
      </ng-container>

      <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
      <mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
    </table>

名称
{{element.sessionName}
日期
{{element.sessionDate}
链接
{{element.sessionLink}
控制

我希望能够获取
name
属性并将其传递给
showdeletemodel()
函数,该函数由每行第四个单元格中的按钮调用。但是,我不能通过执行
{{element.sessionName}}
来访问此数据,否则我如何访问此数据并将其传递给我的函数?

只需传递函数中的
对象即可

这应该起作用:
(单击)=“showDeleteModal(行)”

之后,您可以按如下方式检索名称属性:

showDeleteModal(row) {
   console.log(row.name);
}

将元素传递到fn中不会起作用吗?像这个showDeleteModal(element)?@Qellson这是我尝试的第一件事,但函数在这个上下文中无法解析。如果您按行传递?因为该块的html模板变量是row@Qellson是的,成功了。看起来我让我的头脑变得更困难了。干杯,没问题!干杯:)