如何在Angular中筛选布尔值。

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

How to filter a boolean in angular

问题

所以我需要用这些来表示真和假:

> "pe-7s-close-check pe-lg pe-va text-success" "pe-7s-close-circle
> pe-lg pe-va text-danger"。

我有一个HTML代码:

<tr *ngFor="let invoice of invoices; let i = index">
    <td>{{ i + 1 }}</td>
    <td>{{ invoice.number }}</td>
    <td>{{ invoice.client.name }}</td>
    <td>{{ invoice.paid }}</td>

invoice.paid 是布尔值,所以当它已支付时应该是绿色,未支付时应该是红色,我应该怎么做呢?类似这张图片:

如何在Angular中筛选布尔值。

英文:

So I need to use these for true and false:

> "pe-7s-close-check pe-lg pe-va text-success" "pe-7s-close-circle
> pe-lg pe-va text-danger".

I have a html code:

<tr *ngFor="let invoice of invoices; let i = index">
    <td>{{ i + 1 }}</td>
    <td>{{ invoice.number }}</td>
    <td>{{ invoice.client.name }}</td>
    <td>{{ invoice.paid }}</td>

invoice.paid is the boolean here,so when its paid it sould be green when not paid red how should I do it?
Something like this picture:

如何在Angular中筛选布尔值。

答案1

得分: 1

<tr *ngFor="let invoice of invoices; let i = index">
  <td>{{ i + 1 }}</td>
  <td>{{ invoice.number }}</td>
  <td>{{ invoice.client.name }}</td>
  <td>
    <i [ngClass]="{'pe-7s-close-check pe-lg pe-va text-success': invoice.paid, 'pe-7s-close-circle pe-lg pe-va text-danger': !invoice.paid}"></i>
  </td>
</tr>
英文:
&lt;tr *ngFor=&quot;let invoice of invoices; let i = index&quot;&gt;
  &lt;td&gt;{{ i + 1 }}&lt;/td&gt;
  &lt;td&gt;{{ invoice.number }}&lt;/td&gt;
  &lt;td&gt;{{ invoice.client.name }}&lt;/td&gt;
  &lt;td&gt;
  &lt;i [ngClass]=&quot;{&#39;pe-7s-close-check pe-lg pe-va text-success&#39;: invoice.paid, &#39;pe- 
  7s-close-circle pe-lg pe-va text-danger&#39;: !invoice.paid}&quot;&gt;&lt;/i&gt;
  &lt;/td&gt;
&lt;/tr&gt;

答案2

得分: 0

尝试这个

`&lt;td [ngClass]=&quot;{invoice.paid ? &#39;pe-7s-close-check pe-lg pe-va text-success&#39; : &#39;pe-7s-close-circle pe-lg pe-va text-danger&#39;}&quot;&gt;&lt;/td&gt;`

[Angular ngClass 指令][1]

[1]: https://docs.angularjs.org/api/ng/directive/ngClass
英文:

Try this

&lt;td [ngClass]=&quot;{invoice.paid ? &#39;pe-7s-close-check pe-lg pe-va text-success&#39; : &#39;pe-7s-close-circle pe-lg pe-va text-danger&#39;}&quot;&gt;&lt;/td&gt;

Angular ngClass directive

huangapple
  • 本文由 发表于 2023年7月27日 22:07:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76780578.html
匿名

发表评论

匿名网友

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

确定