Skip to content

Instantly share code, notes, and snippets.

@Kjir
Created February 24, 2016 13:34
Show Gist options
  • Save Kjir/e6e4c1015a23585edd26 to your computer and use it in GitHub Desktop.
Save Kjir/e6e4c1015a23585edd26 to your computer and use it in GitHub Desktop.
$q.all not working exactly as I expected...
<!DOCTYPE html>
<html>
<head>
<script data-require="angular.js@1.5.0" 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>
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