-
-
Save ggondim/9ec3a73411cb5f7c99a5 to your computer and use it in GitHub Desktop.
An Angular.js playground to play with promises. // source http://jsbin.com/yecedi
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
<html> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var $q = angular.injector(['ng']).get('$q'); | |
var $timeout = angular.injector(['ng']).get('$timeout'); | |
function teste() { | |
var deferred = $q.defer(); | |
$timeout(function () { | |
console.log("timeout"); | |
deferred.resolve(1); | |
}, 3000); | |
return deferred.promise; | |
} | |
teste() | |
.then(function (result) { | |
console.log(result); | |
throw "Uncaugth AAAA"; | |
//return 2; | |
}) | |
.catch(function (result) { | |
console.log(result); | |
return 3; | |
}) | |
.then(function (result) { | |
console.log(result); | |
return 4; | |
}) | |
.catch(function (result) { | |
console.log("Uncaugth BBBB"); | |
return 5; | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var $q = angular.injector(['ng']).get('$q'); | |
var $timeout = angular.injector(['ng']).get('$timeout'); | |
function teste() { | |
var deferred = $q.defer(); | |
$timeout(function () { | |
console.log("timeout"); | |
deferred.resolve(1); | |
}, 3000); | |
return deferred.promise; | |
} | |
teste() | |
.then(function (result) { | |
console.log(result); | |
throw "Uncaugth AAAA"; | |
//return 2; | |
}) | |
.catch(function (result) { | |
console.log(result); | |
return 3; | |
}) | |
.then(function (result) { | |
console.log(result); | |
return 4; | |
}) | |
.catch(function (result) { | |
console.log("Uncaugth BBBB"); | |
return 5; | |
});</script></body> | |
</html> |
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
var $q = angular.injector(['ng']).get('$q'); | |
var $timeout = angular.injector(['ng']).get('$timeout'); | |
function teste() { | |
var deferred = $q.defer(); | |
$timeout(function () { | |
console.log("timeout"); | |
deferred.resolve(1); | |
}, 3000); | |
return deferred.promise; | |
} | |
teste() | |
.then(function (result) { | |
console.log(result); | |
throw "Uncaugth AAAA"; | |
//return 2; | |
}) | |
.catch(function (result) { | |
console.log(result); | |
return 3; | |
}) | |
.then(function (result) { | |
console.log(result); | |
return 4; | |
}) | |
.catch(function (result) { | |
console.log("Uncaugth BBBB"); | |
return 5; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment