Here is my JavaScript code:
camListApp.controller("Hello", function($scope, $http, $uibModal){
$scope.del=function(data){
var result=confirm('are you sure?');
if(result==true){
var index=getSelectedIndex(data);
$scope.records.splice(index, 1);
}
};
function getSelectedIndex(data) {
for (var i =0; i<$scope.records.length; i++)
if($scope.records[i].data==data)
return i;
return -1;
}
This is the HTML code snippet:
<td><button class="btn" ng-click="del(record.filename)">Delete</button></td>
This is my JSON data:
[{"cameraid":"000000001","timestamp":"2016-07-09 10:06","filename":"c037731fc2256177ba29c7893caacf04","locationid":"Bedok01"}
{"cameraid":"000000003","timestamp":"2016-07-13 11:35","filename":"4fd2413d30073b4b6a5cacbb8b7c1965","locationid":"Bedok01"}
{"cameraid":"000000003","timestamp":"2016-07-13 14:41","filename":"6b6b62948eb679efeb650d609c85b7aa","locationid":"Bedok01"}
I am trying to implement a delete function in AngularJS that will remove a record when a button is clicked. I also want MongoDB to delete the corresponding data simultaneously. Any assistance on how I can achieve this?