如何在 Angular 2 中订阅 DOMContentLoaded 事件? [英] How to subscribe to DOMContentLoaded event in Angular 2?

查看:33
本文介绍了如何在 Angular 2 中订阅 DOMContentLoaded 事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 UI 主题从 angular 1 移植到 2.在第一个版本中,我有 $viewContentLoaded 事件,我想将其改造成 angular 2.

I'm porting UI theme from angular 1 to 2. In 1-st version I have $viewContentLoaded event and I want remake it to angular 2.

我正在尝试使用 @HostListener('DOMContentLoaded'),但它不起作用(没有任何错误).

I'm trying to use @HostListener('DOMContentLoaded'), but it doesn't work (without any errors).

我该如何解决?或者处理这种情况的最佳方法是什么?

How can I resolve it? Or what is the best approach to handle that?

推荐答案

你不能,DOMContentLoaded 早在第一个组件创建之前就发出了.

You can't, DOMContentLoaded was emitted long before the first component is created.

你可以使用

class AppComponent {
  ngAfterViewInit() {
    // your code here
  }
}

这篇关于如何在 Angular 2 中订阅 DOMContentLoaded 事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆