提交表单后,将调用服务器并显示模式。当服务器响应成功时,必须关闭模态 并加载一个新页面。
我已经尝试过 ng-show、ng-if 来根据 Controller 中的值启用/禁用,但这并没有消除模态背景。我可以使用 data-dismiss="modal"关闭同一页面上的模式,但是在导航到新页面之前如何从 Controller 部分执行此操作?
<div id="myModal" class="modal fade" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<img src="img/processing.gif" id="ajaxSpinnerImage" title="working...">
</div>
</div>
点击提交按钮时
<button type="submit" data-toggle="modal"
data-target="#myModal" ng-click=" formsubmit(orderForm.$valid); ></i>
Place Order </button>
从 Controller 调用服务器
$scope.formsubmit = function (isValid) {
if (isValid) {
$http.post($scope.url).
success(function (data, status) {
//NEED TO CLOSE THE MODAL HERE
//navigating to a new page now
window.location.assign("NewPageToNavigate.html");
})
}
最佳答案
将此 Bootstrap 模态选项连接到服务器响应,模态将关闭:
$('#myModal').modal('hide');
More info and options on the Bootstrap documentation .
关于删除 body 和 backdrop 类,请检查您的代码,因为在正常情况下 Bootstrap 应该在触发上述方法时删除它们。
关于javascript - 从服务器获得响应后关闭 Controller 中的 Bootstrap 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47943545/