我在 AppComponent 类中编写了
@HostListener
来检测浏览器关闭或选项卡关闭。
我已经编写了这段代码,但它不起作用。请帮助我理解为什么我的代码不起作用
下面是我的代码。
export class AppComponent {
@HostListener('window:unload', [ '$event' ])
unloadHandler(event) {
alert('call unload');
}
@HostListener('window:beforeunload', [ '$event' ])
beforeUnloadHander(event) {
alert('call beforeunload');
}
}
使用Angular守卫,Angular中有5种类型的守卫,即CanActivate、CanActivateChild、CanDeactivate、Resolve和CanLoad