How could I make the condition in below code and environment.ts
file.
export const environment = {
production: true,
if(our condiion = "impdev.something.com"){
API_url:'https://impdev.something.com/Angular',
}
if(our condiion = "dev.something.com"){
API_url:'https://dev.something.com/Angular',
}
if(our condiion = "app.something.com"){
API_url:'https://app.something.com/Angular',
}
};
You will achieve this in other way using following solution.
environment.ts
export const environment = {
production: true,
dev: { serviceUrl: 'https://dev.something.com' },
stage: { serviceUrl: 'https://stage.something.com' },
prod: { serviceUrl: 'https://prod.something.com' },
local: { serviceUrl: 'http://localhost:8080/' },
};
NetworkService.ts
export class NetowrkService {
url: string;
env: string
constructor(private http: HttpClient) {
this.env = this.setENV();
this.url = environment[this.env].serviceUrl;
}
setENV() {
if (window.location.hostname.indexOf("dev") != -1) {
return "dev";
} else if (window.location.hostname.indexOf("stage") != -1) {
return "stage";
} else if (window.location.hostname.indexOf("localhost") != -1) {
return "local";
} else {
return "prod";
}
}
// Call rest API
}