I am using a ng-repeat and I want the ng-repeated element to have a conditional ng-class.
I want the conditional to be if the particular item is in an array then apply the condition.
I tried to use jQuery...and it didn't work. Here's what I have:
<tr ng-repeat="user in users" ng-class="($.inArray(user,selectedUser)?'ts-li-selected':''" ng-click="selectUser(user,$event,$index)">
and it's not working...is something like this possible, or will I have to do it more programmatically in the ng-click function?
I am using a ng-repeat and I want the ng-repeated element to have a conditional ng-class.
I want the conditional to be if the particular item is in an array then apply the condition.
I tried to use jQuery...and it didn't work. Here's what I have:
<tr ng-repeat="user in users" ng-class="($.inArray(user,selectedUser)?'ts-li-selected':''" ng-click="selectUser(user,$event,$index)">
and it's not working...is something like this possible, or will I have to do it more programmatically in the ng-click function?
Share Improve this question asked Oct 18, 2013 at 2:45 SnowburntSnowburnt 6,9428 gold badges32 silver badges44 bronze badges1 Answer
Reset to default 7Try
<tr ng-repeat="user in users" ng-class="{'ts-li-selected' : userSelected(user)}" ng-click="selectUser(user,$event,$index)">
then
$scope.userSelected = function(user){
return $.inArray(user, $scope.selectedUser) > -1;
}
Demo: Fiddle