I have a project resource that consists of multiple task resource (similar to Facebook post and comments relationship)
When I update a project, I want to use url /project/[project id]
. and when I update a task, I want to use url /project/[project id]/[task id]
Here is my project resource service:
angular.module('project').factory('Project', ['$resource', function($resource) {
return $resource('project/:projectId', {
projectId: '@_id'
}, {
update: {
method: 'PUT'
}
})
}])
Now I wanna define the task resource:
angular.module('task').factory('Task', ['$resource', function($resource) {
return $resource('project/:projectId/:taskId', {
projectId: '' //how can i pass in the project Id from controller?
taskId: '@_id'
}, {
update: {
method: 'PUT'
}
})
}])
In my controller, if i just update project, not its task, then I simply use:
$scope.update = function() {
$scope.project.$update(function() {
$location.path('project/' + $scope.project._id)
}, function(errResponse) {
$scope.error = errorResponse.data.message
})
}
But when I update the tasks of the project, I wanna pass in the project to construct the url. How can I do that?
Notice that project and task belong to separate modules. user can update the task in project detail page, or in task detail page.