I am using ng-click
function with ng-repeat
. but I want to get the event one time for particular id. and after that if we click on that id then function should not be called for that id.
For example, if I click on id:101 then the function should be called for this id only once. and function will work for other ids. In other words function will be called once for each ids.
My HTML code:
<body ng-controller="AppController">
<table>
<tr ng-repeat="user in users" class="table table-striped table-bordered">
<td>{{user.firstname}}</td>
<td>{{user.lastname}}</td>
<td><a href="javascript:void();" ng-class="{true:'shortlisted',false:'shortlist'}[shortlistStatus == {{user.id}}]" ng-disabled="disable_{{user.id}}" ng-click="shortlist(user.id);" >Shortlist</a></td>
</tr>
</table>
</body>
My controller code:
var app = angular.module('plunker', []);
app.controller('AppController', ['$scope', function($scope) {
$scope.users = [{
firstname: "John",
lastname: 'Doe',
id: "101"
}, {
firstname: "John",
lastname: 'Doe2',
id: "102"
}, {
firstname: "John",
lastname: 'Doe3',
id: "103"
}];
$scope.shortlist = function(val) {
alert(val);
$scope.shortlistStatus = val;
var test = 'disable_' + val;
$scope.test = true;
};
}]);