Reputation: 43
I am working with Angular/typescript and I am getting live data from base and ordering it in table.
My question is how can I change color of text and add different icon based of what do I get. I got this
<td>
{{ item.status49 }}
</td>
[In the end, I would like to have something like this][1] but of course as one or another
And I got 4 possible text status so If else will not work for me, I think
Upvotes: 1
Views: 456
Reputation: 650
You could do:
<div *ngIf="condition1">
your text + your icon
</div>
<div *ngIf="condition2">
text2 + icon2
</div>
<div *ngIf="condition3">
text3 + icon3
</div>
or you can use ng-container:
<td>
<ng-container *ngIf="condition1"> your text + icon</ng-container>
<ng-container *ngIf="condition2"> your text + icon</ng-container>
...
</td>
or
<div [ngSwitch]="item.status49">
<ng-container *ngSwitchCase="'open'"> </ng-container>
<ng-container *ngSwitchCase="'close'"></ng-container>
</div>
Upvotes: 1
Reputation: 910
Use [class]
and change dynamically:
<p [class]="visible ? 'green' : 'red'">
Start editing to see some magic happen :)
</p>
For Reference
Upvotes: 4