ポップアップを開いてユーザーに確認を求めるアプリケーションを作成してから、ajax cal を作成してポップアップを閉じます。私は約束
の連鎖を使ってそれをやろうとしました(私はすでにそれを使っていて、このように動作するはずだと覚えています). 今では、プロミスを返すだけのandで実装された偽のサービスです(将来的には ajax 呼び出しを行います)。これは有効なコードですか、それとも約束の仕組みを理解していませんか?
ポップアップには AngularUI を選択し、コードは次のとおりです。 reservationService.confirm($scope.object);
setTimeout
$q
reservationService.book($scope.object, day)
.then(function(){
var dialogOpts = {/* dialog options omitted*/}
return $dialog.dialog(dialogOpts).open();
})
.then(function(result){
console.log('confirmed? ', result);
if (result){
//After this line it doesn't do nothing, also if the promise is resolved
return reservationService.confirm($scope.object);
}
})
.then(function(){
//this function is never executed
$scope.$emit('object:detail',{object: $scope.object});
});
予約サービス:
function confirm(){
var deferred = $q.defer();
setTimeout(function(){
console.log('Confirming');
deferred.resolve(true)
}, 500);
return deferred.promise;
}
angularのサービスによる解決setTimeout
済みの
変更$timeout