One issue I encountered with my angular app is the need to initialise some resources with a string value. For example:
angular.module('client.core.resources')
.factory('AuthenticationResource', ['$resource','ConstantValueService', function ($resource,ConstantValueService) {
var authUrl = ConstantValueService.get('webApiUri') + '/api/authentication';
return $resource(authUrl, {},
{
login: {
method: 'POST',
isArray: false
},
logout: {
method: 'DELETE',
isArray: false
}
});
}]);
I have a json file with data containing values for a webApiUri that I attempted to use in the following way:
angular.module('myapp').run(['$http',function($http){
$http.get('client.json').success(function (settings) {
ConstantValueService.setFields(settings);
});
}])
Unfortunately, due to the asynchronous nature of the process, the authUrl in the resource gets initialised before the client.json is loaded, resulting in authUrl being undefined.
I am seeking a solution to delay the initialisation and execution of the angular app until the $http promise is resolved. Any suggestions on accomplishing this in an efficient manner would be greatly appreciated.