Home ng-repeat highlight all rows but also deselect, select

# ng-repeat highlight all rows but also deselect, select

user6228
1#
user6228 Published in September 21, 2018, 8:04 am

I have a basic html table where i need to have all the rows initially highlighted when the table is created. Also, if the user clicks the row it un highlights and clicked again highlights.

I have the click on a row, and it highlights. If you click again it un highlights. I just need to initially highlight all rows possibly by ng-repeat. It also needs to release the highlighting when the row is clicked again and then highlight back. userData is just a line of text for each row

HTML

<table class="superusertable" cellpadding="5" cellspacing="0">
<tbody class="table-font">
<tr ng-init="" ng-repeat="source in userData"
ng-model="source.fromSourceID"
ng-class="{'sourcesSelected': source.sourcesSelected}"
ng-click="select(source)">
<td width="290px">
<div class="action-checkbox"; width="290px">{{source.fromSourceID}}
</div>
</td>
</tr>
</tbody>
</table>


angular

 \$scope.select = function(item) {
item.sourcesSelected ? item.sourcesSelected = false : item.sourcesSelected = true;
};

• Not sure what your question is but your code is really verbose and confusing. Just write item.sourcesSelected = !item.sourcesSelected; – Aluan Haddad Feb 13 at 14:45