I have a div that I want to style based on a condition.
If styleOne is true I want a background colour of red. If StyleTwo is true, I want the background colour to be blue. I've got half of it working with the below code.
<div id="myDiv" [ngStyle]="styleOne && {'background-color': 'red'}">
Is it possible to add a condition to say:
- if styleOne is true, do this
- if styleTwo is true, do this?
Edit
I think i've resolved it. It works. Not sure if it's the best way:
<div id="div" [ngStyle]="styleOne && {'background-color': 'red'} || styleTwo && {'background-color': 'blue'}">
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…