0

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 2

1

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>

DEMO PLUNKER

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the Help.Using this a single click on any row will highlight the row.
if you like my answer please correct answer button click @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 .
Please Refer this model code.ciphertrick.com/2014/12/06/… @user3415447
0
<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

why you post my answer again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.