2016-04-04 9 views
2

Gibt es eine Möglichkeit, eine bestimmte Tabellenzeile hervorzuheben?AngularJS, CSS: Hervorhebung einer bestimmten Tabellenzeile

Ich habe eine Tabelle und einen Satz, wenn Winkelcodes zum Beispiel zum Beispiel:

angular.module('myApp', []).controller('myTest', function($scope) { 

var data = []; 
for(var i = 0; i < 10; i++) { 
     data[i] = i; 
} 
$scope.data = data; 

}); 

HTML:

<table ng-app="myApp" ng-controller="myTest"> 
<tr ng-repeat="x in data"> 
     <td > {{ x }} </td> 
</tr> 
</table> 

http://jsfiddle.net/omarjmh/Lvc0u55v/1895/

Gibt es trotzdem, es zu tun, wie

wenn x gleich ist 1 dann css: highlight tr: blau ?

Danke!

+0

http://stackoverflow.com/questions/19375695/angular-ng-style-with-a verwenden -conditional-expression http://stackoverflow.com/questions/31917545/ng-style-with-condition http://stackoverflow.com/questions/18550822/angular-ng-repeat-add-style-on -bedingung Überprüfen Sie diese alle – intekhab

Antwort

2

Verwendung ngStyle:

tr ng-repeat="x in data" ng-style="{'background-color': (x === 1 ? 'blue' : 'white')}" 
+0

danke, es funktioniert –

3

Sie $ selbst und $ ungerade für diese verwenden können.

angular.module('myApp', []).controller('myTest', function($scope) { 
 

 
var data = []; 
 
for(var i = 0; i < 10; i++) { 
 
     data[i] = i; 
 
} 
 
$scope.data = data; 
 

 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app = "myApp"> 
 
    <div ng-controller="myTest"> 
 
<table > 
 
<tr ng-repeat="x in data" ng-style="{'background-color': ($even ? 'green' : 'red')}"> 
 
     <td > {{ x }} </td> 
 
</tr> 
 
</table> 
 
    </div> 
 
</div>

+0

danke. es funktioniert. –

+0

@ YubinQiu, wenn es funktioniert, zögern Sie nicht zu aktualisieren und als Antwort zu markieren! – Dave

Verwandte Themen