I'm building a MEAN stack app, where I need to return a logged in users email address, in order to pass it into a $http.get statement, as a parameter, in order to return data for display.
I am currently trying to do this in a factory, this is the endpoint I have for returning the current logged in user;
$http.get('/api/users/me')
.then(function(result) {
userId = result.data.email;
});
This endpoint works, and if I console.log within the function it will return the email of the logged in user, if I console.log outside, then it returns undefined.
I was wondering if it would be possible to either nest, or use .then or .success in order to pass the returned email address from the original $http.get into a second request, which would look something like this;
$http.get('/api/bets', {params: {"created_by": userId}});
Pretty new to Angular, so if you have any suggestions on where to start with a solution, it would be mighty helpful!