I'm working in an application using angularJs and Bootstrap. I need to display the title of a 'scenario' but changing the Css depending on the status of the scenario and displaying a different icon.
In the beginning I tried this
<span class="text-success" data-ng-if="scenario.status=='success'"><i class="fa fa-check-circle"></i>Scenario {{scenario.title}}</span>
<span class="text-danger" data-ng-if="scenario.status=='fail'"><i class="fa fa-exclamation-circle"></i>Scenario {{scenario.title}}</span>
<span data-ng-if="scenario.status=='none'">Scenario {{scenario.title}}</span>
Which is working fine. But I would like to do it in a more proper way and avoid the duplication of the code so I would like to use ng-class, I have modified the code as following:
<span ng-class="{text-success:scenario.status=='success' || text-danger:scenario.status=='fail'}">Scenario {{scenario.title}}
<i ng-class="{fa fa-check-circle:scenario.status=='success' || fa fa-exclamation-circle:scenario.status=='fail'}"></i>
</span>
However this way is not working and I don't see what is the problem. Could someone please help me?
Thank you!
||syntax is wrong, you need an angular expression that return the classname