I have the following resource definition:
myservices.factory('User', ['$resource',
function($resource){
return $resource('/user/:screenName', {}, {
whoami: {
url: '/user',
method: 'GET',
isArray: false,
params: {
op: 'whoami'
}
},
query: {
url: '/user',
method: 'GET',
isArray: true
},
get: {
method: 'GET',
isArray: false
},
update: {
method:'GET',
params: {
op: 'update'
},
isArray: false,
},
delete: {
method:'GET',
params: {
op: 'delete'
},
isArray: false,
}
});
}]);
and I was thinking it will pass screenName
as the part of URL. Unfortunately, this does not happen.
The controller code is follows:
var user = new User();
user.firstname = $scope.selectedUser.firstName;
user.lastname = $scope.selectedUser.lastName;
user.screenName = $scope.selectedUser.screenName;
user.password1 = $scope.selectedUser.password1;
user.password2 = $scope.selectedUser.password2;
user.roles = $scope.selectedUser.roles;
user.maximalCalories = $scope.selectedUser.maximalCalories;
user.$update();
Actually it passes:
GET http://localhost:8080/user?op=update HTTP/1.1
Host: localhost:8080
...
Accept: application/json, text/plain, */*
...
Referer: http://localhost:8080/app/index.html
i.e. it passes neither parameters except explicit one.
UDPATE
If I do
User.$update(
{
firstname : $scope.selectedUser.firstName,
lastname : $scope.selectedUser.lastName,
screenName : $scope.selectedUser.screenName,
password1 : $scope.selectedUser.password1,
password2 : $scope.selectedUser.password2,
roles : $scope.selectedUser.roles,
maximalCalories : $scope.selectedUser.maximalCalories,
}
);
I get an exception TypeError: User.$update is not a function
UPDATE 2
Apparently, Angular adds function $update
to the object and function update
to the class, and if I have object at LHS
, it will pass only by POST...