Looking to extract a URL from a JSON file and pass it to another JavaScript file that makes an HTTP GET request to execute the URL. This setup involves using one service within another service file to retrieve data. However, upon running the process, the function bannerslides returns 'undefined'.
File: common.js
(function() {
angular.module('siteModule')
.service('loggerService', function ($http, $q)
{ var rox;
var deffered = $q.defer();
$http.get('/config/config.json').then(function (data)
{
deffered.resolve(data);
});
this.getPlayers = function ()
{
return deffered.promise;
}
})
})();
File: siteService.js
(function() {
var confUrl;
angular.module('siteModule')
.service('siteService', function ($http, $q, loggerService)
{
loggerService.getPlayers().then(function (data) {
confUrl = data.data.baseUrl+data.data.urls.site;
console.log("GOTURL",confUrl);
});
this.bannerSlides = function(){
console.log("URL NOT GET",confUrl);
return $http({
method: "GET",
dataType: "json",
url: confUrl
}).then(function (response) {
// inspect/modify the received data and pass it onward
return response.data;
}, function (error) {
// inspect/modify the data and throw a new error or return data
throw error;
});
}
})
})();