Reputation:
I am working Angular Application. I need to display the color of the card according to the condition without duplicating (i.e) creating two cards and displaying with hide and show property.
Example
value of A can yes or no in Array
<div class="card">
<div class="card-titile">Sample</div>
<div class ="card-body">
`
`
` //Some codes
`
`
`
</div>
</div>
If value of A is yes I have to display this card in red and If no, I have to display it in yellow.
Upvotes: 0
Views: 287
Reputation: 16251
You can use [style.color]
<div [style.color]="A == 'yes' ? 'red' : 'yellow'"></div>
If you want to add multi style use ngClass
<div [ngClass]="A == 'yes' ? 'red' : 'yellow'"></div>
Upvotes: 1
Reputation: 1147
You can use ngClass in dom element like
<div [ngClass]="{'red-class': A === 'yes','yellow-class':A === 'no'}">
or you can also apply style conditionally like
<div [ngStyle]="{'color':A == 'yes' ? 'red' : 'yellow'}"></div>
Upvotes: 0
Reputation: 4305
Using an angular expression, add the contents of A
as a class to the card. Then, with css, declare appropriately colored styles for those classes.
Upvotes: 0