I have a users service. I would like to create a method which utilizes another service I have built. There are two methods on this service. getUser()
and getCurrentUser()
. getCurrentUser()
utilizes the injected service which acquires the UID. It uses the returned UID to run the getUser()
method. My problem is that I can't get getCurrentUser()
to return the second tier promise.
This question is a little bit difficult to explain. Here's the code...
svs.service("usersService", function($rootScope, $http, loginService, alertBoxService) {
var self = this;
self.getUser = function(identifier, column) {
if (typeof(column) === 'undefined') column = "uid";
return $http.get($rootScope.api + "/getUser/" + identifier + "/" + column);
}
self.getCurrentUser = function() {
var currentUserPromise;
loginService.getCurrentUid().then(
function(response) {
if (response.data === "false") {
alertBoxService.trigger($rootScope.unexpectedApiResponse);
} else {
console.log(self.getUser(response.data));
currentUserPromise = self.getUser(response.data);
}
}, function(response) {
alertBoxService.trigger($rootScope.asyncFailed);
}
);
return currentUserPromise;
}
});