0

I am into an awkward problem where I need to change the color of the text depending on the situation

here is what I am doing.

ng-style="{'color': 
order.order_status_id === '2' ? 'red' :
order.order_status_id === '3' ? 'green' : 
order.order_status_id === '5' ? 'blue' : 
''}"

The way I am using is kind of a workaround. Is there an actual angular solution for the scenario?

1 Answer 1

2

In my opinion you could do something like this, which is exactly the same but prettier.

In your controller define un object color:

$scope.color = {
  2: 'red',
  3: 'green',
  5: 'blue'
};

Then your ngStyle could be

ng-style="{'color': color[order.order_status_id]}"

That's all ;)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.