0

Using a factory in AngularJS is it possible to change the TokenRestangular URL value.

for example could I do this:

 .factory('projectFactory', ['TokenRestangular', function (TokenRestangular) {
        var factory = {
            projects: []
        };

        factory.get = function () {
            return
             resource = TokenRestangular.all('project');
               resource.getList()
                .then(function (project) {
                    factory.project = project;
                    return factory.project;

                })
        };
        return factory;
    }]);

and in my controller change the value of resource i.e.

   var projects = projectFactory.get()
   projects.TokenRestangular.all('a_different_url');

Hope that makes sense.

0

1 Answer 1

1

It's possible with a service but not with a factory. A service is created as a singleton so each time you inject it you will get the same instance. With a factory you will get a new one.

You should be able to have a simple service like the following and inject it into your controller:

myApp.service('SimpleService', function() {
    this.localValue = 0;
    this.setLocalValue = function(newValue) {
      this.localValue = newValue;
    }
});

Un-tested but should give you enough to go on!

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

2 Comments

> It's possible with a service but not with a factory. --- do you mean the other way around?
@Spike - Nope, I meant it how I said :)

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.