Angular有条件地更改单元格值。

huangapple go评论59阅读模式
英文:

Angular change Cell Value Conditionally

问题

我有一个显示这些数据的表格,我想根据单元格的值来更改表格数据,如果单元格的值为1,我想显示勾号,否则显示单元格的值。
你能帮助我吗?

<ng-container matColumnDef="Monday">
    <th mat-header-cell *matHeaderCellDef> M </th>
    <td mat-cell *matCellDef="let element" [ngClass]="{'make-tick': element.Monday == '1'}"
        [ngClass]="{'make-gold': element.Monday == '0'}"> {{ element.Monday}} </td>
</ng-container>
英文:

I have a grid displaying this data, I want to change the table data based upon cell value if cell values are 1 I have to display tick mark else cell value
can you please help me

&lt;ng-container matColumnDef=&quot;Monday&quot;&gt;
    &lt;th mat-header-cell *matHeaderCellDef&gt; M &lt;/th&gt;
    &lt;td mat-cell *matCellDef=&quot;let element&quot; [ngClass]=&quot;{&#39;make-tick&#39;: element.Monday == &#39;1&#39;}&quot;
        [ngClass]=&quot;{&#39;make-gold&#39;: element.Monday == &#39;0&#39;}&quot;&gt; {{ element.Monday}} &lt;/td&gt;
&lt;/ng-container&gt;

答案1

得分: 1

你可以使用简单的*ngIf来实现这个功能。

<ng-container matColumnDef="Monday">
  <th mat-header-cell *matHeaderCellDef> M </th>
  <td mat-cell *matCellDef="let element" [ngClass]="{'make-tick': element.Monday == '1', 'make-gold': element.Monday == '0'}">
    <ng-container *ngIf="element.Monday != '1'; else tick">
      {{element.Monday}}
    </ng-container>
    <ng-template #tick><!-- 打勾的标记 --></ng-template>
  </td>
</ng-container>
英文:

You can use a simple *ngIf to do that.

&lt;ng-container matColumnDef=&quot;Monday&quot;&gt;
  &lt;th mat-header-cell *matHeaderCellDef&gt; M &lt;/th&gt;
  &lt;td mat-cell *matCellDef=&quot;let element&quot; 
      [ngClass]=&quot;{&#39;make-tick&#39;: element.Monday == &#39;1&#39;, &#39;make-gold&#39;: element.Monday == &#39;0&#39;}&quot;&gt;
    &lt;ng-container *ngIf=&quot;element.Monday != &#39;1&#39;; else tick&quot;&gt;
      {{element.Monday}}
    &lt;/ng-container&gt;
    &lt;ng-template #tick&gt;&lt;!-- markup for tick --&gt;&lt;/ng-template&gt;
  &lt;/td&gt;
&lt;/ng-container&gt;

huangapple
  • 本文由 发表于 2020年1月6日 19:21:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/59611221.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定