Is there a way to style my div based on the ng-repeat index, applying different styles for odd and even rows? The row with an even index should have all classes specified for the odd one plus additional classes.
Controller:
var odd = { 'class1': true, 'class2': true, 'class3': false, 'class4': false };
var even = { 'class1': true, 'class2': true, 'class3': true, 'class4': true };
$scope.applyColumnClasses = function(index) {
if (index % 2 === 0)
return even;
else
return odd;
}
View:
<div ng-repeat="a in articles" ng-class="applyColumnClasses($index)">
I have more than five classes that need to be added to the even row. Is there a more elegant solution? Maybe setting a string variable as "class1, class2" for odd rows, then appending additional classes for even rows before returning it.
I aim to write cleaner code and may benefit from declaring a single object instead of two as I currently have.
Any suggestions or thoughts?