我正在使用Angular 2在我的网站上创建一个Messenger组件。每当用户退出或刷新页面时,我都需要更新上次看到的时间。目前,我的代码在刷新页面时有效,但是在关闭窗口或浏览器时无法正常工作。
这是我的代码:
@HostListener('window:beforeunload', [ '$event' ])
beforeUnloadHandler(event) {
this.updateLastSeen(this.riftId, this.currentSessionChat.hostId,
this.currentSessionChat.id);
return true;
}