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

时间:2019-02-19 13:06:37

标签: javascript android angular lifecycle

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

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

1 个答案:

答案 0 :(得分:2)

您可以在组件上@HostListener的{​​{1}}事件中使用window,如下所示。

focus

您还可以使用export class AnyComponent implements OnInit { @HostListener('window:focus', ['$event']) tabActivation(event) { console.log("TAb activated") } } 事件来检测选项卡的“停用”。

blur