0

I am trying to build links in factory. I need to reach the url variable from template like data-url attribute. The problem is that I don't know how to reach it when I am in factory. Maybe there is some way of using directives to get the data-url attribute ?

myApp.factory('Survey', function ($resource) {
    var url; //I need this value somehow from template
    return $resource(url, {surveyId: '@id'});
});

Or should I use some other method or approach for this?

1
  • I tried $rootScope however when I pass attribute from controller $attrs to $rootScope. It some how executes the factory function before the attributes are actually stored in the $rootScope. Commented Dec 19, 2013 at 9:54

1 Answer 1

2

How about:

myApp.factory('Survey', function ($resource) {
    return {
        fetchStuff: function(url) {
            return $resource(url, {surveyId: '@id'});
        }
    };
});

If you do not want to create an extra function you could always use a provider.

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

2 Comments

I was thinking about this before I posted my question. Could you explain a little bit more about provider ? What is the benefit of choosing provider instead of factory ?
Providers can be configured during the app.config phase. If you like examples by code take a look at this: gist.github.com/Mithrandir0x/3639232

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.