Nepho
Nepho

Reputation: 1112

Angular $resource PUT method, can't make it work

I use a REST api and I'd like to update on of my project objects with a PUT request. The request is supported in the API, and I'm trying to use $resource to PUT the data, but it doesn't seem to work. Here is what I do :

var projectResource = $resource('/api/projects/' + projectId, {update: {method: "PUT"}});
    $scope.editProject = function(editedProject) {
        projectResource.$update(editedProject);
    }

Where editedProject is the project with the new values, filled by a form in a webpage. I know there is something wrong in my projectResource declaration, but I don't find what. Help !

Upvotes: 5

Views: 6773

Answers (2)

KATHERINE
KATHERINE

Reputation: 119

$resource cannot make 'PUT' method, cuz of No 'Access-Control-Allow-Origin'. you can only found the 'OPTIONS' in the networks.In this case, you need to create your PUT call:

var data = $resource('someURL', { jobId: '@jobId'}, { 'update': { method:'PUT' }});
data.update(objectYouWannaUpdate);

Upvotes: 0

species
species

Reputation: 243

Try this:

$resource('/api/projects', { id: projectId }, {
    update: { method: 'PUT' }
});

Upvotes: 15

Related Questions