I can't seem to get an "id" to come through to the $resource
function from the controller. Here is the offending code...
Controller:
$scope.update_user_extra = function () {
UserExtraResource.update($scope.user_extra_details, function (data) {
$scope.user_extra_details = data;
$scope.user_extra_details = {mobile:data.mobile,
landline:data.landline,
position:data.position,
notes:data.notes,
language:data.language};
});
};
Resource:
module.exports = function ($resource) {
return $resource('/api/user_extra/:id/', { id: '@_id' }, {
details: {method: 'GET', url: '/api/user_extra/details'},
update: {method: 'PUT'}
});
};
The GET works fine but the custom PUT returns:
http://127.0.0.1:8000/api/user_extra/ 404 (Not Found)
hardcoding the id like:
return $resource('/api/user_extra/1/', { id: '@_id' }, {
works fine. Any help is much appreciated!!
hmm ... changing this line to:
return $resource('/api/user_extra/:id/', { id: ̶'̶@̶_̶i̶d̶'̶ '@id' }, {
seems to have done it. Thank you very much!
If the default parameter value is prefixed with @, then the value for that parameter will be extracted from the corresponding property on the data object. For example, if the defaultParam
object is {someParam: '@someProp'}
then the value of someParam
will be data.someProp
.
In the above question, the PUT operation was trying to extract the property _id
of the data object when the name of the property was actually id
.
For more information, see AngularJS $resource API Reference.