7

The documentation here says that:

url – {string} – action specific url override. 
The url templating is supported just like for the resource-level urls.

I would like to use this good feature, I tried this:

angular.module("experience", ['ngResource'])

    .factory('Experience', function ($resource, identity) {

    return $resource("api/experiences/:id", {}, {
        queryAll : {
            method  : 'GET',
            url     : 'api/companies/' + identity.id + '/experiences',
            isArray : true
        }
    });
});

You see I am trying to overwrite the url for queryAll method. but this does not work, the query still sends the url api/experiences. is this really supported or I am doing somehting wrong? thanks for any help.

6
  • What version of Angular are you using? I am using this feature successfully with Angular 1.1.4. The difference in my case is the parametric original URL, i.e. I have something like $resource("api/xxx",...) instead of yours $resource("api/xxx/:id",..) Commented Sep 16, 2013 at 10:24
  • thanks for your comment, I am using the newest version 1.2. I guess api/xxx or api/xxx/:id does not affact anything? Commented Sep 16, 2013 at 10:36
  • I guess it should not affect anything, but you never know :) By the way there is another difference: I am using POST, not GET. Commented Sep 16, 2013 at 10:43
  • thanks...I tried both,,,neither works. very strange... Commented Sep 16, 2013 at 10:51
  • This is not working for me either in 1.2.4. Did you figure this out? Commented Dec 17, 2013 at 18:22

2 Answers 2

2

I have a very similar problem in my project. The url couldn't be overridden in resource actions. I am using Angular 1.2.0 and it should support the feature since 1.1.4. So I checked the Angular API reference, CHANGELOG, but no luck. Then I dug into the source code and noticed that the logic of overriding url isn't there. That's the root cause of the problem. I updated Angular to 1.2.0, but I forgot to update angular-resource.js to the corresponding version.

So, long story short: check the version of angular-resource.js

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

Comments

1

I am not sure if you cann access properties of identity in the url override, but you can try something like this:

return $resource("api/experiences/:id", {}, {
    queryAll : {
        method  : 'GET',
        url     : 'api/companies/:id/experiences',
        params  : { id: identity.id },
        isArray : true
    }
});

The id: identity.id tells angular to use the id property of identity, (if it exists).

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.