【问题标题】:how to call function on window close in angular 2如何在角度2中关闭窗口时调用函数
【发布时间】:2018-06-25 00:37:12
【问题描述】:
oauthLogin(app) {
    this.openAuthPopup(
      '/assets/auth.html?socialApp=' + app, () => {
        if (this.SharedService.getAuthorization()) {
          this.checkRegistrationStatus();
          this.SharedService.changeLoggedInStatus(true);
          this.SharedService.changedisplayName(this.SharedService.getDispalyName());
          this.router.navigate(['home/dashboard']); 
        }
      }
    );
}

我的弹窗开启代码

openAuthPopup(url, callback) {
    window.open(url, '_blank');
    callback();
  }

我已经创建了这个函数并从 html 调用这个函数。此功能正在打开一个弹出选项卡。我希望在我的弹出选项卡关闭时检查我的 if 条件,但目前正在发生的事情就像在弹出选项卡上的进程期间检查我的 if 条件。 我被困住了。需要帮助。

提前致谢

【问题讨论】:

  • 注册一个窗口事件

标签: javascript angular popup angular2-forms


【解决方案1】:

我认为您需要使用来自 Angular 的 HostListener 收听事件 beforeunload

@HostListener('window:beforeunload', ['$event'])
beforeunloadHandler(event) {
    // actions
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多