I have a user service. I would like to create a method that uses another service that I created. There are two methods on this service. getUser()and getCurrentUser(). getCurrentUser()uses an introduced service that receives a UID. It uses the returned UID to run the method getUser(). My problem is that I can’t get getCurrentUser()to return a second level promise.
This question is a little difficult to explain. Here is 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;
}
});
source
share