2013-06-01 56 views
1

如何修改此示例以突出顯示green for > 30red for < 20orange for remainder基於條件的不同ng類?

$scope.gridOptions = { 
    data: 'myData', 
    rowTemplate: '<div style="height: 100%" ng-class=" 
             {green: row.getProperty(\'age\') < 30}"> 
         <div ng-repeat="col in visibleColumns()" 
          class="ngCell col{{$index}} {{col.cellClass}}"ng-cell> 
         </div> 
        </div>' 
}; 

color-grid

官方plnkr for the code(並運行它)

回答

2

使用orange作爲默認類,並有條件地申請其他類,但是在CSS中,綠色和紅色應該橙後聲明,所以它會覆蓋橙色。這應該這樣做:

<div style="height: 100%" 
     ng-class="{ green: row.getProperty(age)>30, 
        red: row.getProperty(age) < 20}" 
     class="orange"> 
</div> 

或使用該不在意CSS排序:

<div style="height: 100%" 
     ng-class="{ green: row.getProperty(age)>30, 
        red: row.getProperty(age) < 20, 
        orange: 20 <= row.getProperty(age) <= 30}" > 
</div> 
+0

唉唉,逗號符號。現在這麼簡單,我想到了。謝謝。 –