Reputation: 165
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 ?!
Upvotes: 1
Views: 3651
Reputation: 19622
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
}
Upvotes: 3