I have a list of items in ng-repeat and each of them has a delete button. The action of delete button is some ajax request. My problem is if a user click multiple times on a delete button my api call will get failed because it is deleted in the first click and passing id is not valid in second click . I want to unbind the click after first click and rebind the same on my ajax request success callback.
Here is what I have tried is
HTML
<li ng-repeat="labels in addedLabels track by $index">
{{labels.Label.label_name}}
<button ng-click="removeLabel(labels.label_id, labels.module_id,$index,true,$event);">
</button>
</li>
IN CONTROLLER
$scope.removeLabel = function(label_id,module_id,index,popup,event){
$(event.currentTarget).off('click')
opts.url = SERVER_URL + 'path';
opts.data = {
label_id: label_id,
module_id : module_id
};
$http.post(opts.url,opts.data)
.then(function(response){
// some action
},function(err){
// error action
}).finally(function(){
$(event.currentTarget).on('click')
})