As mentioned by dnc253, referencing the DOM from your controller is not an effective way to develop in Angular. Another way you might do this:
Inject the data in the table into your view from the controller:
.controller('controllerName', ['$scope', function($scope) {
$scope.rows = [
{ col1: 'foo', col2: 'bar', selected: false },
{ col1: 'baz', col2: 'foo', selected: false }
];
}]);
Use the ng-repeat directive to render the models in your view script:
<table>
<tr ng-repeat="row in rows" ng-click="toggleRow(row)">
<td>{{ row.col1 }}</td>
<td>{{ row.col2 }}</td>
</tr>
</table>
Provide the toggleRow
function in your controller to toggle the selected property on your row:
$scope.toggleRow = function (row) {
row.selected = !row.selected;
}
Now you can track the selected rows from your controller, since each row has the selected property.