I am currently utilizing a factory to retrieve a configuration file for my project.
m.factory('clientConfig', function($resource) {
var r;
r = $resource('assets/config.json', {}, {
query: {
method: 'GET'
},
isArray: false
});
return r.query();
});
This configuration file is in JSON format and includes the location of a nodeJS server. In my development environment, the JSON file looks like this:
{
"serverURL": "http://localhost\\:3000"
}
Everything works fine when starting the app on the front page. The clientConfig module is loaded, and subsequent pages use it without any issues, as shown below:
m.factory('House', function($resource, clientConfig) {
return $resource(clientConfig.serverURL + '/houses/:houseId',
...
The problem arises when entering a page that requires immediate data from the server. Since clientConfig is not yet populated, this causes errors with the $resource(clientConfig.serverURL + '/houses/:houseId') call.
My question is whether it is possible to load clientConfig synchronously or delay the start of my app until after clientConfig has been populated?