【问题标题】:Angular material mat-cell Click event角材料垫单元点击事件
【发布时间】:2018-08-31 15:27:08
【问题描述】:

我有一张这样的桌子

<ng-container matColumnDef="position">
  <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
  <mat-cell *matCellDef="let row"> 
        {{row.position}} 
  </mat-cell>

但我想要类似的东西。如果单击单元格,则该单元格将成为该行的输入字段。

<ng-container matColumnDef="position">
  <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>

  <mat-cell *matCellDef="let row" (click)="flag = true"> 
    <ng-container
      *ngIf="flag ? clicked : notClicked">
    </ng-container>

    <ng-template #notClicked>
      <div>
        {{row.position}} 
      </div>
    </ng-template>

    <ng-template #clicked>
      <div>
        <input matInput placeholder="Favorite food" value="{{row.position}}">
      </div>
    </ng-template>

  </mat-cell>

我该怎么做?

注意:我想避免在*.ts 文件中编写逻辑。

【问题讨论】:

    标签: angular angular-material


    【解决方案1】:

    PrimeNG 提供了一些很棒的组件,例如可编辑表格,如果您在其中单击一个单元格,它就会变成一个输入字段。

    参考: https://www.primefaces.org/primeng/#/table/edit

    【讨论】:

    • 问题是关于如何处理有角材料的东西,所以使用另一个框架作为“最终答案”对我来说是错误的
    猜你喜欢
    • 2018-06-18
    • 1970-01-01
    • 2018-12-27
    • 2020-04-20
    • 1970-01-01
    • 1970-01-01
    • 2019-05-05
    • 2022-10-06
    • 2018-04-08
    相关资源
    最近更新 更多