This answer is based on the answer of @Beterraba (but the code example in that answer is incorrect):
Service:
angular.module('myApp.services', [])
.factory('SimpleEmployee', function ($resource) {
return $resource ('/api/employees/:id', { id: '@id' });
})
.factory('Department', function ($resource) {
return $resource ('/api/departments/:id', { id: '@id' });
})
.factory('Employee', ['SimpleEmployee', 'Department', function(SimpleEmployee, Department) {
return {
get: function(params) {
return SimpleEmployee.get({id: params.id}).$promise.then(function (employee) {
employee.departments = [];
angular.forEach(employee.departmentIds, function (departmentId) {
employee.departments.push(Department.get({ id: departmentId }));
});
delete employee.departmentIds;
return employee;
});
}
}
}]);
Controller:
Employee.get({ id: 'me' }).then(function (employee) {
$scope.employee = employee;
});
From AngularJS 1.2 RC3 on you need to unwrap any promise objects on the controller. I found this information here.