2

I'm using AngularJS and Restangular. How can I define the baseUrl to use on run time? I dont think that I can use run or config methods since is the user the one who selects the server to connect to.

I have this so far:

        var rest = Restangular.withConfig(function(RestangularConfigurer){
            RestangularConfigurer.setBaseUrl(baseUrl);
        });

This works fine when using rest to do the calls BUT when Im in need of using Restangular.copy this Restangular does not have the baseUrl defined.

How could I defined the Restangular.baseUrl for the Global/ Singleton one on run time?

1 Answer 1

4

The docs say:

You can set all these configurations in RestangularProvider or Restangular service to change the global configuration [...]

This means, you are able to inject Restangular into your controller, directive, service, ... , and call Restangular.setBaseUrl(baseUrl). I can assure that this works with other configuration methods like setDefaultHttpFields too.

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

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.