我正在使用AngularJs 1.6.1,Bootstrap 4.3和UI Bootstrap4。我有一个很大的表单,提交后会重定向到另一个页面。当表单提交正在执行其异步发布时,我显示一个“正在保存信息...”模式,一旦诺言再次出现,我将触发window.location.href,并在href之后将模式设置为关闭。
vm.save = (
function(goToDetails) {
if (vm.hasError_Overall) {
notificationService.danger("<h5>Error saving customer:</h5><h6>{0}</h6>".format(vm.SaveErrMsg));
} else {
vm.savingCustInfo = true;
api.saveCustomer({
custinfo: theFormData
})
.then(
function(response) {
if (response.error) {
notificationService.danger("<h5>Error saving customer:</h5><h6>{0}</h6>".format(response.error));
vm.savingCustInfo = false;
} else if (response.ErrorMessage) {
notificationService.danger("<h5>Error saving customer:</h5><h6>{0}</h6>".format(response.ErrorMessage));
vm.savingCustInfo = false;
} else {
/* Only run the Dist List save if it's needed */
if (vm.DistLists.length > 0)) {
api.saveDistLists({
distLists: vm.DistLists,
custId: vm.custId
})
.then(
function(dlResponse) {
if (dlResponse.error) {
notificationService.danger(
"<h5>Error saving customer. Unable to save distribution lists.:</h5><h6>{0}</h6>".format(dlResponse.error));
vm.savingCustInfo = false;
} else {
vm.redirectOnSave(goToDetails, isEdit);
}
}
)
.catch(
function(err) {
console.error(err);
notificationService.danger("<h5>An error occurred.</h5><h6>Details: {0}</h6>".format(err.statusText));
vm.savingCustInfo = false;
}
);
} else {
//This is the Redirect!!!
vm.redirectOnSave(goToDetails, isEdit);
}
}
}
)
.catch(
function(err) {
console.error(err);
notificationService.danger("<h5>An error occurred.</h5><h6>Details: {0}</h6>".format(err.statusText));
vm.savingCustInfo = false;
}
);
}
});
vm.redirectOnSave = (
function(goToDetails, isEdit) {
var saveMsg = "<h5>Customer {0} {1} successfully {2}.</h5>".format(vm.FirstName, vm.LastName, isEdit ? "updated" : "created");
notificationMessage.setProperty({
Message: saveMsg,
Success: true
});
if (goToDetails) {
/* redirect to Customer Details */
window.location.href = "/CustomerDetails#/" + vm.custId;
vm.savingCustInfo = false;
} else {
/* redirect to Customer Search */
window.location.href = "Search#/";
vm.savingCustInfo = false;
}
}
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
重定向很有效,并且显示了模式,但是问题是在保存回发完成之后有一小段时间,模式关闭了,并且可以(如果您很快)与表单进行了交互在重定向发生之前。
我将如何保持模式打开更长的时间,以便在重定向发生之前无法触摸表单?