// Retrieve games config object from another service
gamesConfig: gamesConfigService.gamesConfig(),
// Prepare the names of game icons. This support function will be executed in the next method
transformSpace: function(subject) {
var ensuredSubject = subject.toString().toLowerCase();
var transformedSubject = ensuredSubject.replace(/ /g, '_');
return transformedSubject;
},
// Add the iconname property to the game config object
extendGameConfig: function() {
var that = this;
this.gamesConfig
.then(function (response) {
console.log(response.data); // Successfully logs the JSON data
response.data.map(function(obj) {
return new Promise(function(res){
angular.extend(obj, {
iconname: that.transformSpace(obj.attributes.name) + "_icon.png"
});
});
});
}, function () {
console.log('error');
});
This code includes a support method transformSpace
and a main method that seems to have issues passing data correctly (at least, that's what I think).
I am attempting to retrieve this promise in the controller using the following code:
theService.getGamesObj.extendGameConfig()
.then(function (response) {
$scope.allGames = response;
console.log($scope.allGames);
}, function () {
console.log('error')
});
I plan to use the data in the view. However, the current code is not functioning as expected and is returning the following error:
TypeError: Cannot read property 'then' of undefined