I have written a module in angularJS that encapsulates all the backend communications. For greater flexibility I have the api prefix as a constant value on the module (could be
Angular modules, controllers, etc. can be contained within functions, if-statements, etc. They do not have to be at the top level. So, you could include this in your code:
if (environmentOne()) {
module.value('apiPrefix','api1/data');
} else {
module.value('apiPrefix','api2/data');
}
Hope that helps!