Yujia Guo Yujia Guo - 1 month ago 7
AngularJS Question

angularjs if/else if/else (switch) condition

Hi I have a question here
the code and data i have is here

<div class="table-row" ng-repeat="x in myData" >
<div class="table-cell" >{{x.accountNumber}}</div>
<div class="table-cell"><span class="table-cell-asset">
{{x.totalAsset/100|currency}} </span><br/>
<span class="table-cell-changes">{{x.changePercent}}%/

changePercent is a float number that can be positive or negative or 0
i want to add a similar if/else statement to have is change color of changePercent and changeDollar for positive negative or 0.
I know a controller will do the job. I wonder if i can do it with some directive inline code to finish the comparison and change the color by result.


Use ng-class and css rules for your coloring:

<span class="table-cell-changes" 
      ng-class="{'green': x.changePercent > 0, 
                 'yellow': x.changePercent == 0, 
                 'red': x.changePercent < 0}">