2

My question is similar to this one here, I'm creating a new question because I can't comment: How to store the root url of api in angular 4 app?

I like Mike Kovetsky`s answer but I'm not too sure on how to implement in my case, basically I want the user to be able to change the endpoints (pre selected through config files).

So, how can I change API_URL programmatically?

3
  • 1
    What is "API URL" exactly? Commented Jan 19, 2018 at 14:17
  • it's the InjectionToken with the API URL from Mike's answer. It's a fixed URL based on the environment (dev, prod), I want to have multiple urls in dev & prod and have the ability to switch between them. Like this: {provide: API_URL, useValue: environment.apiUrl} Commented Jan 19, 2018 at 14:41
  • It would be easier to use a service that provides that URLs using getters and then depending on a property of the service return different values. Then you just need to set that property to configure the URLs. You can also use something like stackoverflow.com/questions/35655361/… to ensure it is set before any code in services or components is executed. Commented Jan 19, 2018 at 14:53

1 Answer 1

1

I've end up setting up logic inside my interceptor to switch the endpoints, not sure if it's the best solution but will work for the moment.

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.