[英]Is there an AngularJS way to use a browser modal with a promise return?
我的代碼在這里使用自定義模式:
var modalInstance = this.$modal.open({
templateUrl: '/app/tests/partials/markTest.html',
controller: ['$scope', '$modalInstance', 'testService', ($scope, $modalInstance, testService: ITestService) => {
$scope.cancel = () => {
$modalInstance.dismiss('cancel');
};
$scope.ok = () => {
testService.markTest()
.then(() => {
abc().then(() => {
$modalInstance.close();
})
});
$scope.tes = testService;
}]
});
我真的很想使用瀏覽器的內置模式,類似於我嘗試離開要編輯的頁面時在stackoverflow上顯示的模式。
就我而言,這是否有可能,因為在用戶單擊“確定”之后我需要能夠執行某項操作,只有在該操作有效的情況下,我才能關閉模式。
任何提示和建議將不勝感激。
簡單的答案是否定的。 窗口警報/確認對話框被阻止,因此不能與承諾一起使用。
您需要一個HTML /自定義javascript解決方案來實現Promise,例如Angular對話框。
Window.alert()的唯一真正優點是它可以阻止,所以如果您不想阻止,為什么要使用它?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.