Search code examples
angularjsif-statementng-class

how to set ng-class with multiple "OR" condition


I have to set color based on coming details from angular list.

In below code coming data is in string so I have set condition with string

CODE:

<td ng-class="{IsGreen: s.InformationForm == 'Form Completed'  || IsMaroon: s.InformationForm == 'Fill Form'}">
<a href="javascript:void(0);" ng-if="s.InformationForm == 'Form Completed'" class="IsColorWhite">{{s.InformationForm}}</a>
<a href="javascript:void(0);" ng-if="s.InformationForm == 'Fill Form'" class="IsColorWhite">{{s.InformationForm}}</a></td>

Above is code I have done but not working.


Solution

  • It should be:

    <td ng-class="{IsGreen: s.InformationForm == 'Form Completed', IsMaroon: s.InformationForm == 'Fill Form'}">
    

    It doesn't need an either-or statement in there.

    Clearly stated in the AngularJS Documentation