Created
February 24, 2016 13:34
-
-
Save Kjir/e6e4c1015a23585edd26 to your computer and use it in GitHub Desktop.
$q.all not working exactly as I expected...
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script data-require="[email protected]" data-semver="1.5.0" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script> | |
<link rel="stylesheet" href="style.css" /> | |
<script src="script.js"></script> | |
</head> | |
<body ng-app="qall1"> | |
<h1 ng-controller="MyCtrl as ctrl" ng-bind="ctrl.promiseErrors"></h1> | |
</body> | |
</html> |
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 | |
.module('qall1', []) | |
.controller('MyCtrl', function($q) { | |
var vm = this; | |
vm.promiseErrors = "Promise results:"; | |
var deferred1 = $q.defer(); | |
var deferred2 = $q.defer(); | |
var p1 = deferred1.promise.catch(function() { | |
vm.promiseErrors += " Error in first promise"; | |
}); | |
var p2 = deferred2.promise.catch(function() { | |
vm.promiseErrors += " Error in second promise"; | |
}); | |
$q | |
.all([p1, p2]) | |
.then(function() { | |
vm.promiseErrors += " No errors"; | |
}) | |
.catch(function() { | |
vm.promiseErrors += " There were errors"; | |
}); | |
deferred1.resolve("Success!!"); | |
deferred2.reject("Doesn't work"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment