私はAngular UI/ブートストラップ私のプロジェクト内のモーダル。
これが私のモーダルです:
$scope.toggleModal = function () {
$scope.theModal = $modal.open({
animation: true,
templateUrl: 'pages/templates/modal.html',
size: "sm",
scope: $scope
});
}
モーダルを閉じるには、ESCボタンをクリックするか、モーダル領域の外側をクリックします。このような場合に関数を実行する方法はありますか? このような終了をキャッチする方法がよくわかりません。
次のようにすることで、モーダルを手動で閉じることができることはわかっていますng-click="closeModal()"
。
$scope.closeModal = function () {
$scope.theModal.dismiss('cancel');
};
ベストアンサー1
はい、できます。これにより、dismiss イベントが発生し、その場合、promise は拒否されます。また、このメソッドは、promise であるプロパティ$modal.open()
を持つオブジェクトを返すことに注意してください。result
約束すればできる...
//This will run when modal dismisses itself when clicked outside or
//when you explicitly dismiss the modal using .dismiss function.
$scope.theModal.result.catch(function(){
//Do stuff with respect to dismissal
});
//Runs when modal is closed without being dismissed, i.e when you close it
//via $scope.theModal.close(...);
$scope.theModal.result.then(function(datapassedinwhileclosing){
//Do stuff with respect to closure
});
ショートカットとして次のように記述できます:
$scope.theModal.result.then(doClosureFn, doDismissFn);
open メソッドは、次のプロパティを持つオブジェクトであるモーダル インスタンスを返します。
- close(result) - 結果を渡してモーダルを閉じるために使用できるメソッド
- 却下(理由) - 理由を渡してモーダルを却下するために使用できるメソッド
- result - モーダルが閉じられたときに解決され、モーダルが解除されたときに拒否されるプロミス
- opened - コンテンツのテンプレートをダウンロードし、すべての変数を解決した後、モーダルが開かれたときに解決される promise。 'rendered' - モーダルがレンダリングされたときに解決される promise。