I need to apply a conditional class to a div. The issue I am facing is that I want the "myClassCondition" to be a string as shown below. When I use
<div [class]="7 > 6 ? 'bg-red' : null"> MyText </div>
, it works perfectly. However, I want to pass it from a .ts
file as a variable like this. How can I achieve this?
<div [class]="myClassCondition"> MyText </div>
-
myClassCondition = "7 > 6 ? 'bg-red' : null";