1
votes

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 ?!

1

1 Answers

3
votes

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

Layout Component

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

Template

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