角度检测是否打开了弹出窗口 [英] Angular detect if a popup window is opened

查看:73
本文介绍了角度检测是否打开了弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的董事会(用Angular 4编写)中,对话框如下所示打开:

In my board (written in Angular 4), the dialogues are opened like below:

导入已激活的路由,路由器

Importing ActivatedRoute, Router

从'@ angular/router'导入{ActivatedRoute,Router};

在构造函数中添加路由器和ActivatedRoute引用

Adding Router and ActivatedRoute references in constructor

构造函数(...private _router:路由器,private _activatedRoute:ActivatedRoute,...)

并按以下方式使用

And Using it in below way

this._router.navigate(['./',{出口:{somemodal:'somemodal',对话框:null},relativeTo:this._activatedRoute}]));

要求是,当您点击转义 Esc 时,它应显示删除模式(已实施且正在运行的其他模式).

Requirement is when you hit escape Esc it should show the removal modal (an other modal already implemented and working).

但是质量检查人员提出了一个问题 ,例如当出现其他弹出式窗口(如扫描的检查图像/重新扫描弹出式窗口/客户ID弹出式窗口/错误消息弹出式窗口)时,KBD> Esc 这些弹出窗口应先关闭.

But QA has raised an issue like when other popups (like scanned check image/ rescan popup / customer id popup / error message popups) are present then on hit Esc those popups should close first.

如果不存在其他弹出窗口,则仅删除"模式将打开,目前还没有发生.在命中 Esc 时,它仍会打开删除弹出窗口.

If no other popup are present, then only Removal modal will open, which is not happening at present. On hit Esc it is still opening the removal popup.

问题:如何检测是否存在其他弹出窗口.

Question: How can I detect if other popups are present.

注意:在开发的最初阶段,在某些共享服务中,我们可以创建诸如 isPopupOpened:boolean = true 之类的标志,并在关闭同一弹出窗口时转到 isPopupOpened = false .但这尚未实现,并且已实现了几种模式,这些模式在我的董事会的不同阶段均已打开.用户可能会在任意时间点点击 Esc .所以我想如何解决相同的问题.

Note : At the very beginning of development, in some shared service, we could have created flag like isPopupOpened: boolean = true and on closing the same popup it should be turned to isPopupOpened = false. But this is not implemented and several modals are implemented, which all are opened in different stages in my board. An user may hit Esc at nay point of time. So I want to what is the solution of the same.

推荐答案

我找到了解决方案.

keyCommandHandler(command: Command): void {
        switch (command.name) {
          case 'App.Escape':
          if (this._router.url.indexOf('dialogs') === -1  && this._router.url.indexOf('subdialogs') === -1) {
            this.cancelHelper();
          }else {
            this._router.navigate(['./', { outlets: { dialogs: null }, relativeTo: this._activatedRoute }]);
          }
            break;
        }
      }

只需检查URL中是否存在任何对话框或子对话框.它对我有用.

Just check if any dialogs or subdialogs is present in your URL. It works for me.

这篇关于角度检测是否打开了弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆