I'm facing an issue with a function that should return a list of favorite locations. Here's the code snippet in question:
When I call LocationsFactory.getFavoriteLocations(), it returns a promise like this:
getFavoriteLocations: function() {
if (favorite_locations.length == 0)
{
var deff = $q.defer();
obj.getDeviceId().then(function(device_id) {
$http.get('url?token=' + device_id).then(function(response) {
favorite_locations = response.data;
deff.resolve(favorite_locations);
return deff.promise;
})
})
} else {
return favorite_locations;
}
}
The getDeviceId function also uses promises to retrieve a key:
getDeviceId: function() {
var deff = $q.defer();
deff.resolve(Keychain.getKey());
return deff.promise;
}
However, when trying to chain these promises together, I encountered an error saying "TypeError: Cannot read property 'then' of undefined." Can someone provide some guidance on how to resolve this issue?