Search code examples
angularjsangular-ui-bootstrapconfirm

angularjs DELETE FUNCTION ask the client if he is sure to delete


Hey i have a delete function works on http:

$scope.RemoveWorker=function(workerid){
    $http.delete("/ShiftWeb/rest/admin/removeworker?id="+workerid)
            .then(function(response){$scope.removeworker=response.data;
            alert("Worker " + workerid + " Deleted");
            $state.reload()
            console.log(response.data);
            }, function(error) {
                alert(error.data);
            }
            );
};

anybody knows how do i ask the client if he sure he wants to delete it or not. if he say no then dont delete it. help please :)


Solution

  • You can modify the function as below using confirm function in which you can enter any message that will prompt user

    $scope.RemoveWorker=function(workerid){
        if(confirm("Do you really want to delete this record ?")){
            $http.delete("/ShiftWeb/rest/admin/removeworker?id="+workerid)
                 .then(function(response){$scope.removeworker=response.data;
                   alert("Worker " + workerid + " Deleted");
                   $state.reload()
                  console.log(response.data);
                  }, function(error) {
                        alert(error.data);
                 });
         }
    };