首页 > 解决方案 > 如何在Angular中更新表格的单个单元格?

问题描述

我正在尝试更新该单列悬停时的表格单元格,而不是相同内容的所有列。这是更新我的 ngswitchCase 待处理的所有列,但我只希望该特定行的表中的单个单元格获取更新/呈现不同的按钮。

<div [ngSwitch]="rowData['dataFromJson']">
  <div *ngSwitchCase="'pending'">
    <div *ngIf="condition"; then thenBlock; else elseBlock">
    </div>
    <ng-template #thenBlock>
      <button (mouseover)="condition=!condition">A</button>
    </ng-template>
    <ng-template #elseBlock>
      <button (mouseleave)="condition=!condition">B</button>

    </ng-template>
  </div>

标签: javascripthtmlangulartypescriptangular6

解决方案


假设我们看到的是一个更大模板的片段,而不是组件的整个模板:如果组件condition之间共享一个属性,那么对于每个人来说它当然是真或假。制作condition一个数组(每行一个条目)。

或者,将上述内容作为一个单独的组件,condition然后将其包含在其范围内。


推荐阅读