user2389087
user2389087

Reputation: 1762

Multiple conditions on ngstyle

I would like to if possible add multiple conditions to ng style

Currently I set the width and color like this

[ngStyle]="{
              'width': (question.score.toFixed(1) * 10)+'%', 
              'background-color': question.score.toFixed(1) < 3 ?'red' : '#00c9c7' 
              }"

However I want to score under 3 are red, and over 7 are green. This condition gives me under 3 are red, anything else is turquoise. Are you able to add multiple conditions to ng style?

Upvotes: 4

Views: 4260

Answers (1)

ValLeNain
ValLeNain

Reputation: 2304

I strongly advise to make a function in your js code to be called, instead of writing it inline.

But it would be:

question.score.toFixed(1) < 3 ? 'red' : question.score.toFixed(1) > 7 ? 'green' : '#00c9c7'

Upvotes: 5

Related Questions