1

I am using angular resource in order to retrieve a record from my AP.
Below is my relevant controller information.

$scope.formInformation = formService.get({id:$state.params.form_id });

Below is my service

    (function(){
        "use strict";

        angular
        .module("mainAppModule")
        .factory("formService", formService);

        function formService($resource)
        {
            return $resource(apiLink + 'form/:id',
                //{id: '@_id'}, //this breaks it
                {
                    'query' : {
                    method: 'GET',
                    isArray: true,
                    }
                },
                {
                    'get' : {
                    method: 'GET',
                    url: apiLink + 'form/individualForm/:id',


                    }
                }
            );
        }
    })();

When I try to overwrite the url variable, it still uses the original one which is.

"apiLink +"form/:id" 

as opposed to

apiLink + 'form/individualForm/:id',

which should be overwritten by the following line.

 url: apiLink + 'form/individualForm/:id',

but when I remove.

{id:'@id'},

My url is overwritten.
I am trying to understand why that is the case.
I am using angular and angular resource version 1.7.7.

2
  • Please include the code you use to "overwrite the url variable". And explain what you mean when you say "uses the original one". Commented Feb 25, 2019 at 22:45
  • Updated my question. url is what is used to overwrite the url Commented Feb 25, 2019 at 22:51

1 Answer 1

1

The actions parameter is malformed:

    function formService($resource)
    {
        return $resource(apiLink + 'form/:id',
            //{id: '@_id'}, //this breaks it
            {
                'query' : {
                method: 'GET',
                isArray: true,
                }
            ̶ ̶}̶,̶
            ̶{̶
                'get' : {
                method: 'GET',
                url: apiLink + 'form/individualForm/:id',

                }
            }
        );
    }

The actions parameter should be a hash of all the resource actions. When the actions were spread over two objects, only the first object overrode the default. The action declaration for get was ignored and the default was used.

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.