单击关闭/关闭ng-bootstrap模态会导致页面滚动到顶部

时间:2019-04-30 09:51:57

标签: javascript angular typescript ng-bootstrap

我目前正在与Ng-Boostrap's modal合作。

在模态中,我有一个反应形式。

由于某种原因,当我单击关闭按钮,提交按钮或在模态区域之外单击以关闭/关闭模态时,将导致页面在模态关闭后一直滚动到顶部。

我可以知道是否有人遇到过类似的问题,并且有解决方案吗?我绝对不希望将其滚动到页面顶部。

这是我在component.html上的模态代码:

<!--begin::Modal-->
<ng-template #content let-d="dismiss">
  <div class="modal-header">
    <h4 class="modal-title" id="product-allocation-settings">Product Allocation</h4>
    <button type="button" class="close" aria-label="Close" (click)="d('Cross click')">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body">
    <form [formGroup]="productAllocationForm">
      <!-- other irrelevant form fields -->
    </form>
  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-outline-dark" (click)="d('Submit')">Submit</button>
  </div>
</ng-template>
<!--end::Modal-->

在我的component.ts上,它处理模态内表单的提交。这也关闭了模态。

this.modalService.open(content, { size: 'lg', centered: true }).result.then(() => {

}, (reason) => {
  if (reason === 'Submit') {
    this.save();
  }
});

我尝试了以下解决方案,但似乎没有任何运气。

1)Prevent page scroll after click?

2)Prevent browser jump to top page when submit the form

0 个答案:

没有答案
相关问题