1

is it possible to define a static variable based on environment?

Something like (this code is a silly example but it holds the idea):

if (environment.production) {
   public static MY_VAR: string = 'A';
} else {
   public static MY_VAR: string = 'B';
}

Thanks for any advice!

2
  • 4
    public static MY_VAR = environment.production ? 'A' : 'B' ? Commented Apr 6, 2017 at 11:20
  • Thanks that is the solution! Commented Apr 6, 2017 at 11:26

1 Answer 1

1

what i do is read the url from window.location.host when the application is bootstrapped for the first time and then according to the dev,qa and uat url i set the api endpoint in my application. How to achieve this?

in your main.ts file

 platformBrowserDynamic([{provide:'EndPoint',useValue:config.getEndPoint()}])

export class config{
public static getEndPoint(){
const host = window.location.host
if(host) // your logic goes here{

}
}
}

In your service inject it like

constructor(@Inject('EndPoint') private endPoint:string)
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.