-3

I have the a Status parameter for my HTML table which could take values such as :

  • SUCCESS

  • FAILURE

  • IN PROGRESS

I want to surround the text with a specific color depending on the value it takes. I am working with Angular 4 (HTML and TypeScript).

Any pointers to solve this problem?

Abhijeet Mohanty
  • 334
  • 1
  • 6
  • 21
  • 1
    Define styles in a class for each status and toggle that class using `ngClass`. Example, `[ngClass]="{'success': status === 'SUCCESS', 'failure': status === 'FAILURE', 'in-progress': status === 'IN PROGRESS'}"` – karthikaruna Nov 16 '17 at 06:21
  • What exactly do you mean by "surround the text with a specific color"? Text stroke? Shadow? Background? Border around the text element? What does your HTML look like right now? – Brad Nov 16 '17 at 06:23
  • @Brad Background precisely. – Abhijeet Mohanty Nov 16 '17 at 06:24
  • @AbhijeetMohanty `background: #f7f;` – Brad Nov 16 '17 at 06:24
  • @Brad Yes I know that, what my question is how do I vary background color depending on the content of the text. – Abhijeet Mohanty Nov 16 '17 at 06:26

1 Answers1

0

Try this, I did not test this but hope this helps:

[ngStyle]="{'background-color':status === 'SUCCESS' ? 'green' : status === 'FAILURE' ? 'red' : 'blue'}
D. Pareek
  • 709
  • 4
  • 12