javascript - Highlight selected row in ng-repeat with logic only in HTML -
this follow question of how highlight selected row in ngrepeat?
here row being highlighted using function defined in controller.i wanted make other way round,where want use code in html. below plunker have tried . plunker pls share thoughts on issue:
<tr ng-repeat="item in items" ng-init="selectedrow = null" ng-class="{'selected':selectedrow == $index}" ng-click="selectedrow=$index" ></tr>
have @ demo
<tr ng-repeat="item in items" ng-init="selectedrow = null" ng-class="{'selected':$parent.selectedrow == $index}" ng-click="$parent.selectedrow=$index" > <td>{{item.name}}</td> <td>{{item.value}}</td> <td><button class="btn btn-primary" ng-click="edit(item)">click</button></td> </tr>
function listctrl($scope, $dialog) { $scope.items = [ {name: 'foo', value: 'foo value',car:'chevy',model:'vette',year:'2013'}, {name: 'bar', value: 'bar value'}, {name: 'baz', value: 'baz value'} ]; $scope.selected = -1; }
Comments
Post a Comment