Ionic 2 enviroment variables


#1

Good morning,

In my app I would to setup enviroment variables. I need to specify different addresses for my enviroments ( development, staging, production). How can I do this ? Someone can help me ?

Thanks in advance,

Mattia.


#2

I don’t know that it’s necessarily the best way, but this has been working for me so far just for differentiating local ionic serve dev and the live app.

export class MyService {
    endpoint: string = 'https://myproduction.endpoint/';
    api_key: string = '123456abcdefg';

    constructor() {

        // this is local dev with ionic serve
        if (window.location.href.startsWith('http://localhost:8100/')) {
           this.endpoint = 'http://testendpoint.local';
           this.api_key = '78910hijklmn';
        }
    }
}

#3

Good morning,

thank you so much !