【问题标题】:Angular Mat dialog closes and moves to top left of page in IEAngular Mat 对话框关闭并移动到 IE 页面的左上角
【发布时间】:2019-12-19 00:21:06
【问题描述】:

当用户选择提交按钮时,我会弹出一个确认模式。

当模态出现时,用户可以选择单击按钮来关闭模态。下面是它的样子:

HTML:

<ng-template #confirmModal>
  <custom-modal-body-component 
    (cancelFn)="closeModal()"
  </custom-modal-body-component>
</ng-template>

TS:

  @ViewChild('confirmModal', { static: true }) confirmModalTemplate: TemplateRef<any>;

  constructor(
    private modalService: MatDialog,
  ) {}

  submit() {
    this.myModal = this.modalService.open(this.confirmModalTemplate);
  }

  closeModal() {
    this.myModal.close();
  }

我的问题是,当用户关闭模式时,它会在关闭前短暂移动到页面的左上角。我不希望这种情况发生。

我希望模态框能正常关闭而不跳到页面的左上角。我们最近将 Angular/material 从 7.x.x 升级到了 8.2.1。此问题未出现在版本 7 中,我们不想降级到 7。对可能发生的情况有什么想法吗?

这只发生在 IE 中,我们需要支持。

编辑: 应该注意的是,这种行为只发生在我们应用程序的两个特定页面上。我们在所有页面上以相同的方式打开模式,但此问题并非在所有页面上都存在。

【问题讨论】:

    标签: html angular typescript angular-material modal-dialog


    【解决方案1】:

    这可能是超出区域的问题。尝试将模型的关闭和打开放在区域内,如下所示:

        constructor(private zone: NgZone) { }
    
        const dialogRef1 = this.zone.run(() => {
            this.dialog.open(DialogComponent, {});
        });
    

    【讨论】:

    • 这个解决方案确实改变了跳到屏幕左上角的模态行为,尽管它确实从我的潜在原因列表中划掉了一个项目。
    猜你喜欢
    • 2012-11-01
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多