blu10
blu10

Reputation: 654

delete from a local json file

Newbie angular question but im trying to figure out how to delete elements from a local json file

I'm reading them back correctly and have them displayed on my page. I have a Remove button with ng-click calling the removeRow function below which removes an item from the scope (thus removing them from the screen). I want to permanently remove them from the json file though...

I was looking at http.delete but couldnt find any good examples of what i needed... is this the correct function to use?..

just to add im using a node js http server without any rest endpoints configured. It this a must to use delete, post etc?

.controller('View1Ctrl', ['$scope','$http', function($scope, $http) {

    $scope.tables = {};

    $http.get('test.json').success(function (data){
      $scope.tables = data;
    });

   $scope.removeRow = function(idx) {

      $scope.tables.splice(idx, 1); 

   }


}]);

Upvotes: 1

Views: 1442

Answers (1)

Zee
Zee

Reputation: 8488

Yes a server is a must to create/delete/manipulate a file. You can make a $http call(delete) to your nodeJS server, which in turn should do what you want using fs module.

I would suggest, pass the key-value pairs to your server using the $http call and use fs to make changes to the corrosponding file.

Upvotes: 3

Related Questions