我做了一些更多的研究,我發現another question與此類似,這是對這個問題找到了答案(隨意+1他,而不是我)
$scope.$on('modal.closing', function(event, reason, closed) {
var r = prompt("Are you sure you wanna close the modal? (Enter 'YES' to close)");
if (r !== 'YES') {
event.preventDefault();
}
});
將這個內部模態控制器。
這不完全是您搜索的內容,如果您嘗試關閉模式,可以通過關閉(單擊外部模式),取消或確定按鈕來提示您。您可以嘗試並修改它以滿足您的需求。
更新:新增簡單if else
檢查,看看到底點擊了哪個,如果點擊背景,然後提示用戶:
$scope.$on('modal.closing', function(event, reason, closed) {
if (reason == 'ok' || reason == 'cancel'){
console.log('closed');
} else {
// this is if 'reason' == 'backdrop click'
var r = prompt("Are you sure you wanna close the modal? (Enter 'YES' to close)");
if (r !== 'YES') {
event.preventDefault();
}
}
});
你認爲這個解決方案是足夠了嗎?
當你關閉模式就像一個事件觸發,在我看來,你可以以某種方式工作,我認爲這個問題可以幫助你:http://stackoverflow.com/questions/30356844/angularjs-bootstrap- modal-closing-call-when-clicking-outside-esc – klskl
我不認爲有必要使用boostrap的模態。您可以簡單地創建一個z-index大於零的div/form。並根據需要使用ng-hide/ng-show使隱藏/可見。 – SaiGiridhar
@SaiGiridhar好吧,我必須在項目中使用它,這是一個要求。最後一次我做模態它只是VanillaJS :) – Georgy