My angular app has some resources that I need to initialise with a string, e.g:
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
}
});
}]);
Now I have some data in an external json file that contain values for a webApiUri. I tried to do the following:
angular.module('myapp').run(['$http',function($http){
$http.get('client.json').success(function (settings) {
ConstantValueService.setFields(settings);
});
}])
However, as it is an async process, tracing shows that in the above mentioned resource, authUrl gets initialised way before client.json is loaded. So in resource the authUrl = undefined.
I would like to know if there is a nice way to postpone initialising and running of the angular app until the $http
promise is fulfilled.