Zerzio
Zerzio

Reputation: 249

AngularJS resource : how to update

I'm using express-resource on the server. In my AngularJS controller:

    var User = $resource('/services/users/:userId', {userId:'@id'},
        { update: {method:'PUT'} }
    );
    $scope.save = function(user) {
        user.$update(function(u) { console.log("User " + u)});
    }

The PUT method should go to /services/users/2 but it's actually sent to /services/users So I get a 404

BTW, the user ID field if UserID (not userId or id) but I don't understand how am I supposed to declare the URL.

Upvotes: 2

Views: 3096

Answers (1)

Zerzio
Zerzio

Reputation: 249

Ok, after digging a bit I found

var User = $resource('/services/users/:id', {id:'@UserID'},
    { update: {method:'PUT'} }
);

Upvotes: 7

Related Questions