I need to GET data from a rest API, with the product id part of the url (and not as query parameter).
The factory:
.factory('Products', ['$resource',
function($resource) {
return $resource('products/:productId', {
productId: '@id'
}, {
query: {
isArray: false
},
update: {
method: 'PUT'
}
});
}
])
The controller:
$scope.getProduct = function(id, from) {
$scope.product = Products.get({ id: id }, function(){
console.log($scope.product);
});
}
My url is constructed like:
/products?id=5426ced88b49d2e402402205
instead of:
/products/5426ced88b49d2e402402205
Any ideas why?
@
prefixed value then? "If the parameter value is prefixed with @ then the value for that parameter will be extracted from the corresponding property on thedata
object (provided when calling an action method). For example, if thedefaultParam
object is{someParam: '@someProp'}
then the value ofsomeParam
will bedata.someProp
." Sounds like you should be able to pass in anid
value and the resource would use it to populate theproductId
param. But this is not the case. – Alec