Can someone explain why the second promise returned by then function is resolved? It looks like Angular JS bug in its Promises implementation. According to the documentation here the second promise should also have been rejected.
// Code goes here
var myMod = angular.module("myMod", []);
myMod.controller('bodyCtrl', function($scope, $timeout, $q) {
var deferred = $q.defer();
deferred.promise.then(function(d) {
console.log("success called");
return d;
}, function(d) {
console.log("failure called");
return d;
})
.then(function(d) {
console.log("success called2");
return d;
}, function(d) {
console.log("failure called2");
return d;
});
$timeout(function() {
deferred.reject();
}, 2 * 1000);
});
<!DOCTYPE html>
<html ng-app="myMod">
<head>
<script src="https://code.angularjs.org/1.5.8/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-controller="bodyCtrl">
<h1>Hello Plunker!</h1>
</body>
</html>