I am creting a table using ng-repeat in angularjs, and i want to change background colour of row on button click. Like on clicking yes green colour should be set and on no button red colour is set. can somebody help please
2 Answers
Each row has an ID. All you have to do is to send this ID to the function setSelected(), store it (in $scope.idSelectedVote for instance), and then check for each row if the selected ID is the same as the current one. Here is a solution(see the documentation or ngClass, if needed);
$scope.idSelectedVote = null;
$scope.setSelected = function (idSelectedVote) {
$scope.idSelectedVote = idSelectedVote;
};
.
<ul ng-repeat="vote in votes" ng-click="setSelected(vote.id)" ng-class="{selected: vote.id === idSelectedVote}">
...
</ul>
4 Comments
user3415447
Thanks for the Help.Using this a single click on any row will highlight the row.
Ivin Raj
if you like my answer please correct answer button click @user3415447
user3415447
Thanks for the Help.Using this a single click on any row will highlight the row. I want to select a row on a single button click.Can you please help .
Ivin Raj
Please Refer this model code.ciphertrick.com/2014/12/06/… @user3415447
<ul ng-repeat="vote in votes" ng-click="setSelected(vote.id)" ng-class="
{selected: vote.id === idSelectedVote}">
...
</ul>
in controller
$scope.idSelectedVote = null;
$scope.setSelected = function (idSelectedVote) {
$scope.idSelectedVote = idSelectedVote;
};
refer:http://plnkr.co/edit/SkaYSbtKFdx1I9N0xP5E?p=preview
1 Comment
Ivin Raj
why you post my answer again