Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to disable clicked button inside ng-repeat using its index

What I have tried:

how to disable clicked button inside ng-repeat using its index
Posted
Updated 29-May-16 23:28pm
Comments
Karthik_Mahalingam 30-May-16 3:09am    
why do you need index for that?
It can be done without $index object.
[no name] 30-May-16 3:11am    
because it is inside ng-repeat and i want to disable that particular button which i clicked
Karthik_Mahalingam 30-May-16 3:35am    
It is applicable to all buttons or specific to some button
[no name] 30-May-16 3:42am    
applicable to the button which i click not specific
Karthik_Mahalingam 30-May-16 5:27am    
ok fine. i got.

1 solution

try this

HTML
<!DOCTYPE html>
<html lang="en-US">
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

    <!--<script src="angular.js"></script>-->
    <script>
        var app = angular.module('myapp', []);
        app.controller('myctrl', myfun);
        function myfun($scope) {
            $scope.items = [{ Name: 'apple' }, { Name: 'banana' }, { Name: 'carrot' }, { Name: 'drumstick' }, { Name: 'egg' }];

            $scope.disablethis = function (btn) {
                btn.target.disabled = true;
            }
        }

    </script>


</head>
<body ng-controller="myctrl" ng-app="myapp">

    <ul>
        <li ng-repeat="item in items">
            <button ng-click="disablethis($event)">{{item.Name}}</button>
        </li>
    </ul>

</body>
</html>


demo: JSFiddle[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900