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!

Italo Borges
  • 2,355
  • 5
  • 34
  • 45

1 Answers1

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

Community
  • 1
  • 1
Italo Borges
  • 2,355
  • 5
  • 34
  • 45