Delete Function Not Working With Angularjs
my js code: camListApp.controller('Hello', function($scope, $http, $uibModal){ $scope.del=function(data){ var result=confirm('are you sure?'); if(result==true
Solution 1:
First of all you need to open an endpoint in your server. Mongodb is a database and thus you can access it from your backend, by implementing a controller or something similar. Then you can make an API call to that endpoint.
$scope.del = function(data) {
$http.post('/records/' + data.id + '/delete')
.then(function(){
.... the rest of your angular code goes here
})
};
Solution 2:
make http call to delete from db and then remove the object from list using splice as below
<td><button class="btn" ng-click="del(record)">Delete</button></td>
$scope.del = function(record) {
var index = $scope.records.indexOf(record);
$scope.records.splice(index , 1);
$scope.list();
};
Post a Comment for "Delete Function Not Working With Angularjs"