【发布时间】:2019-11-25 04:03:09
【问题描述】:
嘿,我尝试在关闭选项卡上发出 http 请求,但它不起作用, 但是如果我导航到其他组件它的工作。 我尝试像这篇文章一样更改功能Angular 2 - Execute code when closing window
但它现在对我有用。
我的 http 服务:
removeCurrentEditor(reportID) {
return this.http.request('GET', this.baseUrl + this.REPORTS_API + '/' + this.REMOVE_CURRENT_EDITOR
+ '/' + reportID, {responseType: 'json'});
}
我的组件:
// Handle close tab
@HostListener('window:beforeunload', ['$event'])
beforeUnloadHander(event) {
this.reportService.removeCurrentEditor(this.reportID);
}
谢谢!
【问题讨论】:
标签: angular