Good afternoon,
I'm new to angularJS, so sorry if I ask a basic question ... but I have a problem:
I have a service (Service2) that takes a string from a configuration, and I have another service (Service1) that using this service2 to do some more operations and returns a URL(return of service2 + operations on service1)... However, in function initialize () it skips the execution of
Service2.getConfig().then(function (config) {
baseUrl = config.endPointUrl;
});
And goes straight to return. Getting incomplete the URL what I need... Would you have any suggestions on how to get it to return service1 only after doing everything from service2?
Here's the basic code I'm trying to do
Service 1
function Service1($resource, Service2) {
var resourceUrl = "";
var baseUrl = "";
initialize();
function initialize() {
Service2.getConfig().then(function (config) {
baseUrl = config.endPointUrl;
});
resourceUrl = baseUrl + "/event/history/period";
}
return $resource(resourceUrl, {}, {
'query': { method: 'GET', isArray: true }
});
}
Service2
function service2($resource, $log) {
var configService = {};
configService.getConfig = getConfigFromServer;
return configService;
function getConfigFromServer() {
var eventDataResource = $resource('api/service-config');
return eventDataResource.get().$promise;
}
}