Created
January 27, 2015 16:58
-
-
Save Kikketer/e6f4f7f7b8626f7c2005 to your computer and use it in GitHub Desktop.
Synchronous Environment Injection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
angular.module('yourModule') | |
.factory('environmentService', function() { | |
var environment; | |
return { | |
getEnvironment: function() { | |
// We need this to be synchronous since everything depends on it. | |
// If we return a promise, there is a cascading change (not fun) | |
if (!environment) { | |
$.ajax('environment', {async: false}) | |
.success(function(env) { | |
environment = env; | |
return environment; | |
}) | |
.error(function() { | |
throw 'Environment variables not set'; | |
}); | |
} | |
return environment; | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment