我有一個Angular-UI模式的表單。當用戶觸發dismiss事件時,我想實現基於$ dirty的確認。我已經搜索了很多來源,找到Promise的概念,並可以成功地獲得在結束活動期間發出警報。但是,我無法找到任何地方如何實際停止模式關閉。確認角度模態關閉在髒的表格
編輯:
隨着當前代碼確認警報常(令人驚訝的並不總是)的模式已經被駁回後彈出。
var editResourceModalController = function($scope, $uibModalInstance) {
$uibModalInstance.result.catch(function() {
if ($scope.editForm.$dirty) {
window.confirm("close modal?");
}
$uibModalInstance.dismiss('cancel');
});
}
var uibModalInstance;
$scope.openEditModal = function() {
uibModalInstance = $uibModal.open({
animation: true,
templateUrl: "edit.html",
controller: editResourceModalController
});
}
謝謝您的回答。但是,我不想僅將它掛鉤到一個按鈕單擊,我想要捕獲單擊和ESC按鈕忽略事件。此外,如果用戶選擇取消,我仍然不知道如何阻止模式實際關閉。我可以使用'preventDefault()'嗎? –
爲什麼不爲這些事件設置監聽器並按照你的意願處理它們? – atefth
你能更具體一點嗎? –