繁体   English   中英

Angular 中是否有类似于 Android View Lifecycle 的 onResume 方法?

[英]Is there an onResume method in Angular similar to Android View Lifecycle?

在我的应用程序中,用户可以在多个选项卡之间切换。 每个选项卡都链接到不同的组件。

示例:用户在 URL1 上,单击按钮时,他导航到新选项卡中的 URL2。 当我手动切换回 URL1 时,是否有任何方法可以像Android onResume函数一样触发?

您可以在组件上的window focus事件上使用@HostListener ,如下所示。

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")
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM