$http.delete local json file


#1

Hi,

I’m trying to delete a favorite object I have saved in a local JSON file by clicking the remove button that I have placed behind every favorite item.

I already posted my question with fully details on Stackoverflow but I’m not receiving a lot of responses.

Hopefully someone can take a look at it and help me out, so I can go on with my first iOnic project.

Thanks!


#2

Few comments:

This:

<a class="button button-icon icon ion-trash-b col" ng-click="removeFavo(favo.id)">

should be this:

<a class="button button-icon icon ion-trash-b col" ng-click="removeFavo({{favo.id}})">

In the first case, JavaScript don’t know what favo.id is.

Further more, this:

$scope.removeFavo = function(data) {
    myFavos.deleteFavo(favo);
}

should be this:

$scope.removeFavo = function(data) {
    myFavos.deleteFavo(data);
}

variable favo don’t exist, on the other hand variable data holds the id.

Further more, this:

deleteFavo: function(favo) {
  $http.delete('data/favos/' + favos.id + '.json').success(function (data) {
    return callback(data);
  });
},

should be this:

deleteFavo: function(favo) {
  $http.delete('data/favos/' + favo + '.json').success(function (data) {
    return callback(data);
  });
},

Variable favo holds the id

Alos don’t forget to debug your application, all of these errors should be visible in console log. Fine more about it here: http://www.gajotres.net/how-to-properly-debug-your-ionic-application/


#3

Thanks! I’m a step closer now!
The only error I’m still getting now in the console is this:

DELETE http://localhost:8100/data/favos/[object%20object].json 404 (Not Found)


#4

JavaScript can’t access your JSON file. You will need to check path of said JSON file.


#5

That’s strange :confused: , because I’m using the same path as the GET request(that does work) to show a list of the favorite items in the favos.json file.


#6

Can it not be something with permissions or headers that causes that I’m not allowed to edit the file?