Created
August 27, 2014 20:55
-
-
Save bmakarand2009/a1df26123f5630c9b5f9 to your computer and use it in GitHub Desktop.
highlight the selected row in a table when user clicks it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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