関数によって返された2番目の約束がなぜ解決されるのか説明できますか?これはPromises実装のAngular JSバグのようです。文書hereによると、2番目の約束事も却下されているはずです。Angularは、メインプロミスが拒否されたときに "then"関数によって返された約束を解決します。
// 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>
http://stackoverflow.com/questions/18758058/angularjs-promise-rejection-chaining –
@georgeawg ...に関連する...次の例(PLUNKER)を参照するか、 '$のq.rejectを返します() ' –