Closed dportabella closed 8 years ago
Good question. In chapter 2, it's ok either way. However, in chapter 5, we start using $resource
and we need to specify the name of the parameter that matches a route, like this:
// https://github.com/amejiarosario/meanshop/blob/ch5/client/app/products/products.service.js
angular.module('meanshopApp')
.factory('Product', function ($resource) {
return $resource('/api/products/:id', null, {
'update': { method: 'PUT'}
});
});
Notice that we are using a placeholder called :id
. When we use the controller we need to match it as follows:
// https://github.com/amejiarosario/meanshop/blob/ch5/client/app/products/products.controller.js
$scope.product = Product.get({id: $stateParams.id});
I see. thanks.
Is there any reason why in chapter 2, the
get
function of the product service takes an objectparams
(with only one fieldid
) as a parameter, instead of just a simple parameterproductId
?you have:
why not simply?