Created
August 19, 2013 02:45
-
-
Save jhdavids8/6265389 to your computer and use it in GitHub Desktop.
Angular service that fetches and stores the current, logged-in user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module("PathgatherApp").factory 'CurrentUser', (["$q", "Restangular", ($q, Rectangular) -> | |
current_user = null | |
current_user_promise = Restangular.all("users").customGET("current") | |
current_user_promise.then (response) -> | |
current_user = response | |
{ | |
getUser: () -> | |
if current_user? | |
deferred = $q.defer() | |
deferred.resolve(current_user) | |
return deferred.promise | |
else | |
return current_user_promise | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment