In my AnlgularJS controller, my first order of business is to determine if the app is running in dev, or test.
For that purpoer, I make a call to an api, an an answer back (that part is verified to work).
Depending on the environment, I need to set the value for the $scope.uploadUrl, so my file uploader directive would know which url is to target for its file uploads.
For some reason, by the time the uploader is executed, that url value is lost.
Here is the relevant part of my controller:
$scope.uploadUrl = '';
console.log('This is FileUploadController');
function getEnvironment (){
$http.get('/environment').success(function(response) {
$scope.currentEnvironment = response.environment;
if(response.environment === 'test'){
$scope.uploadUrl = 'http://test_url:3001/api/files';
}
if(response.environment === 'dev'){
$scope.uploadUrl = 'http://dev_url:3000/api/files';
}
console.log('Current Environment is: ' + $scope.currentEnvironment
+ ' so the uploadUrl should be: ' + $scope.uploadUrl);
});
}
getEnvironment();
var selectedCategory;
var selectedDataVersion;
var uploader = $scope.uploader = new FileUploader({
//url: 'http://dctool-lnx.cloudapp.net:3001/api/files',
url: $scope.uploadUrl,
tabName: 'sheet1'
});
What is the proper way to re-structure this code, to make the value, set within my getEnvironment function to live long enough?