SO - 28230232 - AngularJS first occurrenced value manipulate from JSON data
by codeSpy
HTML
<table ng-controller="PlayerController">
<tr ng-repeat="player in player_history">
<td ng-class="(player.award=='y' || player.award=='Y') && $index == firstYFound ? 'firstY' : 'restAll'">{{player.description}}</td>
</tr>
</table>
CSS
.firstY{
color : green;
}
.restAll{
color : blue;
}
JavaScript
data = [
{
"value": "10",
"description": "rooney",
"award": "N"
},
{
"value": "7",
"description": "di maria",
"award": "N"
},
{
"value": "1",
"description": "de gea",
"award": "N"
},
{
"value": "16",
"description": "carrick",
"award": "Y"
}
];
function PlayerController($scope){
$scope.player_history = data;
for(var i = 0; i < $scope.player_history.length; i++){
if($scope.player_history[i].award.toLowerCase() == "y"){
$scope.firstYFound = i;
break;
}
}
}