Quantcast
Channel: Conditionally style text in Angular2 - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by Aravind for Conditionally style text in Angular2

$
0
0

You can use class property binding

<p *ngFor="let item of data"><span [class.blue]="item.number === 1" [class.red]="item.number === 2" [class.green]="item.number === 3"> {{item.name}} </span> </p>

Alternatively you can use the [style.color] property binding

<p *ngFor="let item of data"><span [style.color]="getColor(item.number)">{{item.name}}</span></p>getColor(number){    if(number ===1 ){        return 'blue';        }else if(number ===2 )          {            return 'red';         } else if(number ===3 )            {                return 'green';           }else {            return '';            }}

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>