Last active
January 6, 2016 20:37
-
-
Save icfantv/e6db5bcd8a9a5520ff78 to your computer and use it in GitHub Desktop.
AuthService with promise and cache
This file contains hidden or 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.service('AuthService', function($q, $http) { | |
var authStuff, promise; | |
this.login = function(credentials) { | |
if (!authStuff) { | |
promise = $http.post(...).then(function(response) { authStuff = response.data; }); | |
} | |
return $q(function(resolve, reject) { | |
promise.then(resolve(...)).catch(reject(...)); | |
}); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perhaps?