0

I am trying to make the request

....port/trimService/fragments/?fragment_name=:fragmentName

However if I try to make the "?fragment_name" a parameter, it breaks. As I am going to have more requests, my action with change so I cannot leave it in the url portion of the resource.

angular.module(foo).factory('FragmentService', ['$resource',
function ($resource)
{
    var FragmentService = $resource('.../fragments/:action:fragmentName',
    {},
    {
        'getFragments':
        {
            method: 'GET',
            isArray: true,
            params:
            {
                fragmentName: "@fragmentName",
                action: "?fragment_name="
            }
        }

    });
    return FragmentService;
}
]);

As of right now, I have no idea what my URL is actually outputting.

EDIT: I changed my resource as /u/akonsu had mentioned below. I also added my controller as it is still not working correctly.

angular.module(foo).factory('FragmentService', ['$resource',
function ($resource)
{
    var FragmentService = $resource('.../fragments/',
    {},
    {
        'getFragments':
        {
            method: 'GET',
            isArray: true,
            params:
            {
                fragmentName: "@fragmentName",
            }
        }

    });
    return FragmentService;
}
]);


angular.module(foo).controller('FragmentController', ['$scope', 'FragmentService',
function ($scope, FragmentService)
{
    $scope.fragmentQuery = {
        fragmentName: 'a',
    };


    $scope.fragmentQuery.execute = function ()
    {
        if ($scope.fragmentQuery.fragmentName == '')
        {
            $scope.fragments = {};
        }
        else
        {
            $scope.fragments = FragmentService.getFragments(
            {
                fragmentName: $scope.fragmentQuery.fragmentName,
            });
        }
    };
    $scope.fragmentQuery.execute();

}

]);

2
  • what is the URL that it sends a request to now? could you see it in the network tab in the browser? Commented Aug 1, 2013 at 16:23
  • Yes, I was finally able to see the call, I hadn't been able to, this led me to be able to make the proper changes to my controller. Thank you! Commented Aug 1, 2013 at 16:45

1 Answer 1

1

Try omitting the query string altogether in the resource URL and just supply your fragmentName as a parameter to the action call. It should add it to the query string if it is not in the list of URL parameters.

$resource(".../port/trimService/fragments/").get({fragmentName: 'blah'})
Sign up to request clarification or add additional context in comments.

2 Comments

The problem seems to lie in the ? mark in the action, I cannot find any work around for this, I'd really like to keep the query string as I am going to have multiple requests later.
you can use your query string, as I said, if your params are not found in the URL pattern then angular adds them to the query string.

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.