ionic 3 dynamic class (ngClass)

hashbyte picture hashbyte · May 4, 2018 · Viewed 13.1k times · Source

So I am pretty new to this. I using Ionic 3 and trying to dynamically choose which class to use based on a condition but I cannot get ngClass to work... Any help would be appreciated.

    <div ng-class="test: data[i].complete ? 'completed' : 'notCompleted'>
      <div class="dueDate">{{ data[i].dueDate }}</div>
      <div class="taskLabel">{{ data[i].taskLabel }}</div>
      <div class="checkBox">
        <img src="{{ data[i].complete_url }}" style="width : 100% ; height : 100%" (click)="CheckBox(i)">
      </div>
    </div>

Answer

Sajeetharan picture Sajeetharan · May 4, 2018

You are using angularjs syntax wih angular, it should be something like this,

[ngClass]="test===data[i].complete?'completed':'my-notCompleted'"