2015-11-26 52 views
1

當複選框的值爲true時,我想將背景顏色更改爲lightblue,並在值爲false時將背景顏色更改回正常。AngularJs複選框函數

<tr ng-repeat="item in rows | filter:search" ng-class="{'selected':$index == selectedRow}"> 

我的複選框:

<td><input type="checkbox" ng-click="setClickedRow($index)"></td> 

我的功能:

$scope.selected = null; 
$scope.setClickedRow = function(index){ 
    $scope.selectedRow = index; 
} 

回答

1

在這裏,你有你的例如plunker:http://plnkr.co/edit/CHB65fe6Bsd3PdjWjoT4?p=preview

這是表:

<table style="width:100%"> 
<tr ng-repeat="item in rows | filter:search" ng-class="{'selected': item.selected}"> 
    <td> 
    <input type="checkbox" ng-model= "item.selected" ng-click="setClickedRow($index)"> 
    </td> 
</tr> 
</table>