如何检测布局组件中是否加载了新的角度组件? [英] How to detect a new angular component is loaded in layout component?

查看:56
本文介绍了如何检测布局组件中是否加载了新的角度组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个有角度的项目,该项目使用"router-outlet"将组件渲染到布局中.如您所知,布局的ngOnInit仅在第一次加载时用完,并且当新组件加载到布局中时,布局的ngOnInit不会再次运行..我想知道如何在布局中检测到新组件.有没有办法知道?!

We have an angular project that uses "router-outlet" to render components into layout (component) .. As you know, the layout's ngOnInit runs out only for the first time of load and when a new component loads into the layout, layout's ngOnInit doesn't run again .. I'm looking for to know how to detect a new component is loaded in the layout .. Is there a way to know ?!

推荐答案

对同一事件使用 activate 事件.每当我们在路由器插座中加载组件时,都会触发激活事件.

Make use of activate event for the same . Whenever we load a component in router outlet a activate event is emitted .

布局组件

  <div class="container">
    <router-outlet (activate)="onActivate($event)"></router-outlet>
  </div>

模板

  onActivate(componentRef){
    // fires every time a new component is loaded
  }

这篇关于如何检测布局组件中是否加载了新的角度组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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