javascript - 在销毁角度上调用http请求
问题描述
http请求未执行
@HostListener('window:beforeunload')
async ngOnDestroy() {
await this.microSitioService.cancelarTransaccion(this.tarjetaCreditoService.seguimientoEtapa).then(() => {});
}
执行 on destroy 时我需要执行 http 请求
解决方案
如果您正在寻找在 Angular 应用程序被销毁时执行的事件,您可以使用PlatformRef
具有OnDestroy()
回调的
在 main.ts
function doSomethingOnAppDestory() {
console.log('test');
}
platformBrowserDynamic().bootstrapModule(AppModule).then(ref => {
// Ensure Angular destroys itself on hot reloads.
if (window['ngRef']) {
window['ngRef'].destroy();
}
window['ngRef'] = ref;
ref.onDestroy(doSomethingOnAppDestory);
// Otherwise, log the boot error
}).catch(err => console.error(err));
推荐阅读
- ruby - 如何在循环中放回输出令牌 - Ruby Pagination?
- node.js - 如何在没有逗号的情况下将缓冲区写入文件?(节点)
- c# - 反射:检查 Type 是否满足 new() 约束
- c++11 - 为什么编译器抱怨可以静态排除的路径(见下面的代码)?
- unity3d - 有什么办法可以在 Unity 中使用 SteamVR 摆脱屏幕镜像?
- reporting-services - 数据库表值/字符串更改时如何更新 SSRS 文本框
- c# - 无法为桌面桥应用程序、UWP 的 Windows 打包项目创建 bundle.appxupload 文件
- json - 找不到“@types”的类型定义文件
- android - Android 使用 libvlc 将实时视频流保存到存储
- r - 如何选择不包含特定字符的列?