Last active
November 10, 2015 05:05
-
-
Save YashdalfTheGray/504abce74e073ce5c7b7 to your computer and use it in GitHub Desktop.
Wrapping other async tasks
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
// assume that getUsers returns a promise but | |
// the service may not be written in angular | |
$q.when(service.getUsers()).then(function(result) { | |
ctrl.userList = result; | |
}); | |
// $q.when() can also be useful when writing stubs | |
function getUsers() { | |
// this function is supposed to return a promise | |
// but in test, it doesn't make sense to do that | |
// so use $q.when() to return an immediately | |
// resolving promise. | |
return $q.when(_userList); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment