Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

my js 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;
        }

Html code:

  <td><button class="btn" ng-click="del(record.filename)">Delete</button></td>

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"}

How can i do a delete function on angularjs and when the button is clicked and at the same time mongodb also remove the data. Anybody can help?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
188 views
Welcome To Ask or Share your Answers For Others

1 Answer

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
       })
   };

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...