最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ngclass expressions, is value in an array - Stack Overflow

programmeradmin6浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 7

Try

<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

发布评论

评论列表(0)

  1. 暂无评论