I am trying to use ng-class to apply conditional formatting within an ng-repeat. The condition should be based on evaluation of an object data string.
I am trying to get his code to apply bold to the 3rd item. I have done my best at trying $eval
or $parse
to no avail.
<body ng-app="examsApp">
<div ng-controller="ExamsController as examsList">
<div ng-repeat="exam in examsList.exams">
<span ng-repeat="levelnum in exam.levels.levelnums" ng-class="{ 'bold': $eval(exam.levels.evalby[$index]) }">
{{levelnum}}
</span>
</div>
</div>
</body>
var data = [
{
"id": "exam1",
"text": "Exam 1",
"levels":
{
"levelnums": ['2', '3', '4', '5'],
"evalby": ['$scope.bold === 0', '$scope.bold ==== 1', '$scope.bold === 2', '$scope.bold === 3']
}
}
]
angular.module('examsApp', [])
.controller('ExamsController', ['$scope', function ($scope) {
var examsList = this;
examsList.exams = data;
$scope.bold = 2;
}])
Your plunk has a handful of small issues, two of which can be found by opening the developer console:
angularJS
.ng-repeat
over examsList.exams
outside of the div
that is assigned the examList
controller
.eval
array.eval
array currently resolve to false
.css
rule for the bold
class defined.