I've been using custom actions in a few repositories. And up until now I only had to specify the url and the method.
For example:
updatePassword: {
url: ENV.NITRO_PROJECT_REST_URL + '/admins/:adminId/password',
method: 'PUT'
}
But then, I had to code a custom action that had, not one, but two path parameters:
technicianModule.controller('technician.teamCtrl',
['$scope', '$state', '$stateParams', 'CommonService', 'TechnicianService', 'TeamService', 'TeamTechnicianService',
function($scope, $state, $stateParams, CommonService, TechnicianService, TeamService, TeamTechnicianService) {
$scope.add = function(teamId) {
TeamTechnicianService.add(teamId, $stateParams.technicianId, function() {
TeamService.get(teamId, function(data) {
$scope.teams.push(data);
$scope.unassignedTeams.splice(CommonService.getResourceIndex($scope.unassignedTeams, data), 1);
});
});
};
}
]);
teamModule.factory('TeamTechnicianService',
['RESTService',
function(RESTService) {
var factory = {};
factory.add = function(teamId, technicianId, callback) {
return RESTService.TeamTechnician.add({teamId: teamId, technicianId: technicianId}).$promise.then(callback);
}
return factory;
}
]);
So I first coded it like:
TeamTechnician: $resource(ENV.NITRO_PROJECT_REST_URL + '/teamtechnicians/:teamtechnicianId', {}, {
add: {
url: ENV.NITRO_PROJECT_REST_URL + '/teamtechnicians/:teamId/:technicianId',
method: 'POST'
}
But it would not work. The parameters were not passed in.
After a few tries I found out it worked when adding some parameter definition, right before the custom action definition.
It had to be like:
TeamTechnician: $resource(ENV.NITRO_PROJECT_REST_URL + '/teamtechnicians/:teamtechnicianId', {
teamId: '@teamId',
technicianId: '@technicianId'
}, {
add: {
url: ENV.NITRO_PROJECT_REST_URL + '/teamtechnicians/:teamId/:technicianId',
method: 'POST'
}
Note the presence of:
teamId: '@teamId',
technicianId: '@technicianId'
My understanding was then that in a $resource definition, a custom action that has more than one path parameter, requires them to be defined with @ signs.
And not when it has only one.
Why is that ?
And why can't the path parameters be declared in the custom action instead of above in the resource ?