在我的应用程序中,用户可以在多个选项卡之间切换。每个选项卡都链接到不同的组件。
示例:用户在URL1上,单击按钮,他在新选项卡中导航到URL2。当我手动切换回URL1时,是否有任何方法可以像onResume
中的Android
函数一样触发?
您可以在@HostListener
的window
事件中使用focus
,如下所示。
export class AnyComponent implements OnInit {
@HostListener('window:focus', ['$event'])
tabActivation(event) {
console.log("TAb activated")
}
}
您还可以使用blur
事件来检测选项卡的“停用”。
@HostListener('window:blur', ['$event'])
tabDeactivation(event) {
console.log("TAb deactivated")
}