angularjs - .get() Url is not what i expect -
angularjs - .get() Url is not what i expect -
i'm trying angular.js first time. have rest service configured next way:
get('/api/users') //returns json array users get('/api/users/:id') //returns json object requested id
my angular controller set this:
userctrl.factory('user', function($resource) { homecoming $resource('/api/users/:id', { id: '@id' }, { update: { method: 'put' } }); }); var editctrl = function($scope, $location, $routeparams, user){ var id = $routeparams._id; $scope.user = user.get({id: id}); };
my problem when run
user.get({id: id})
the url requested is:
http://localhost:8080/api/users?id=389498473294
i want
http://localhost:8080/api/users/389498473294
i can using $http
, think .get()
should able it...
thanks
you define default value id parameter prefixed @, means value must taken object passed parameter call. in phone call there no object sent, id parameter assigned null value. beingness id parameter assigned, value pass appended query parameter. explanation of @ angular documentation under usage/param defaults paragraph. right way declare service should be:
userctrl.factory('user', function($resource) { homecoming $resource('/api/users/:id', { id: '' }, { update: { method: 'put' } }); });
angularjs
Comments
Post a Comment