I am trying to using ng class ternary operator to toggle class when a check box is selected.
Here is the simple code: http://jsfiddle.net/vqmua1x2/
I am expecting text content to turn bold and unbold when check box is selected.
I am not able to find what is my mistake.
HTML code:
<div ng-app="myApp">
<div ng-controller="Ctrl1">
<header>
<h1>Problems</h1>
</header>
<div id="problems">
<table>
<tr>
<td>
<input type="checkbox" ng-model="val1"/>
</td>
<td>prob1</td>
</tr>
<tr>
<td>
<input type="checkbox" ng-model="val2"/>
</td>
<td>prob2</td>
</tr>
</table>
</div>
<div>
<header>
<h1>Orders</h1>
<ul>
<li ng-class="{{val1 }}? 'bold' : 'unbold'">prob1</li>
<li ng-class="{{val2 }}? 'bold' : 'unbold'">prob2</li>
</ul>
</header>
</div>
</div>
Javascript:
var myApp = angular.module('myApp', []);
myApp.controller('Ctrl1', ['$scope', '$rootScope', '$window', function ($scope, $rootScope, $window) {
$scope.val1 = false;
$scope.val2 = false;
}]);
CSS:
.bold {
font-style:none;
font-weight:bold;
}
.unbold {
font-style:none;
font-weight:bold;
}
ng-class="{bold:val1}"but I haven't tested. Edit: updated your fiddle, that is the answer. jsFiddle