How to add multiple if statements in a div

I wanna add multiple conditions in one div in order to change the color dynamically like this:

<div tappable  [style.background]= "if x=1 let color be red ; if x=2 let color be green ;if x=3 let color be blue">

I know how to use it for two conditions with the “?”. but I am new to ionic and could not apply multi conditions.

maybe it is easier with

 [style.background]= "myvariable"

and in your .ts file you set our variable like you want.

case 1:
myvariable = 'red';
case 2:
myvariable = 'green';
throw 'x ist nix';

Maybe this helps:

Best regards, anna-liebt

Look at ngStyle and ngClass.

1 Like