angularjsangular-resource

OverWriting URL using angular resource not working


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.


Solution

  • 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.