How do I color the selected line on a table?
I have the following code:
<tr ng-repeat="p in produtos" ng-click="info(p)"
ng-class="{'info': ??}">
I just can not find a condition to color only the selected line.
Does anyone have an idea?
How do I color the selected line on a table?
I have the following code:
<tr ng-repeat="p in produtos" ng-click="info(p)"
ng-class="{'info': ??}">
I just can not find a condition to color only the selected line.
Does anyone have an idea?
One solution would be to create a variable:
$scope.selected = '';
And when you click on a tr
assign the $ index or element id to this variable, then just check what the value is and apply the class, like this:
<tr ng-repeat="p in produtos" ng-click="selected = $index" ng-class="{'info': selected == $index}">
See a working example: link
If your intention is to check and uncheck, one option is to create a boleana
variable that will be "turned on or off" when clicking.
.azul {
color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><divng-app="" ng-init="names=['Jani','Hege','Kai']">
<ul>
<li
ng-repeat="x in names"
ng-click="selected = !selected"
ng-class="{'azul': selected}">
{{ x }} - {{ $index }}
</li>
</ul>
</div>
This way you can sort all the items at the same time, which then I realized that it does not answer the AP question, but it can be useful.