Angular2-beforeunload在浏览器/窗口关闭时不起作用

时间:2018-07-05 23:20:46

标签: angular

我正在使用Angular 2在我的网站上创建一个Messenger组件。每当用户退出或刷新页面时,我都需要更新上次看到的时间。目前,我的代码在刷新页面时有效,但是在关闭窗口或浏览器时无法正常工作。

这是我的代码:

@HostListener('window:beforeunload', [ '$event' ])
beforeUnloadHandler(event) {
    this.updateLastSeen(this.riftId, this.currentSessionChat.hostId, 
    this.currentSessionChat.id);
    return true;
}

0 个答案:

没有答案
相关问题