Search code examples
angularng-class

Angular2 - ng-class not applying css


I'm just trying to implement a condition row formatting in a table but it is not working.

The code is very simple:

styles

<style type="text/css">
  .red {
    color: red;
  }

  .blue {
    color: blue;
  }
</style>

html component

<tr *ngFor="let c of customers" [class.selected]="c === selectedItem" ng-class="{1==1 ? 'red': 'blue'}">

The condition 1==1 is always true, and should render the red class, but it doesn't apply either red or blue class.


Solution

  • I created this example.

    <div>
      <h2 [ngClass]="1==1?'red':'blue'">Hello {{name}}</h2>
    </div>