0

is this possible with AngularJS Resource?

/api/client/:id/jobs (get all the jobs from this client)

/api/client/:id/job/:jobId (get the job form this client)

My Factory:

.factory('Client', ['$resource', 'Api',
    function ($resource, Api) {

        var Client = $resource(Api.url() + 'client/:id/',
            {
                id: '@id'
            },
            {
                'update'   : { method: 'PUT',  isArray: false }
            }
        );

        return Client;
    }
]);

Thanks!

1 Answer 1

0

I found a solution for my problem.

I have to create another factory to do the job:

.factory('ClientJobs', ['$resource', 'Api',
    function ($resource, Api) {

        var ClientJobs = $resource(Api.url() + 'client/:clientId/job/:jobId',
            {
                clientId: '@Id',
                jobId: '@Id'
            },
            {
                'query':  { method: 'GET', isArray: true },
                'update': { method: 'PUT' }
            }
        );

        return ClientJobs;
    }
]);

And, i can use the factory like this:

ClientJobs.save({clientId:clientId, jobId:job.id}, job, function (result) {
            deferred.resolve(result);
        }, function (reason) {
            deferred.reject(reason);
        });

Now, everything is working.

And for help those people who are working with UI-ROUTER, there is this question with an excellent answer about complex states like mine and nested views:

Nested Views with Nested States

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.