Skip to content

Instantly share code, notes, and snippets.

@bmakarand2009
Created August 27, 2014 20:55
Show Gist options
  • Save bmakarand2009/a1df26123f5630c9b5f9 to your computer and use it in GitHub Desktop.
Save bmakarand2009/a1df26123f5630c9b5f9 to your computer and use it in GitHub Desktop.
highlight the selected row in a table when user clicks it
//Step 1. on ng-click call a method and pass the $index to it. say select($index).
//Note - $index is a property of ng-Repeat and represents the index of the selected row
<div ng-controller ="MyCtrl">
<tr ng-repeat="car in cars" ng-click="select($index)">
<td>..</td>
<tr>
</div>
//Step2 - On MyCtrl Controller, store the index
$scope.select = function(index){
$scope.index = index
}
//Step 3- Add ng-Class directive to row , here we are applying the info class in when the index is selected
<tr ng-repeat="car in cars" ng-click="select($index)" ng-class="{'info':$index == index}">
//enjoy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment