I upgraded angular2 application to stable release (from rc1), and noticed that ngOnDestroy
is not triggered when route params are changed.
With previous version, when changing url from match/123
to match/124
, onDestroy was called and I was able to do some cleaning (e.g. unsubscribing from websocket for that particular match).
With this new behaviour, I'm not sure what is the best way to do the same? Can I force component to be re-initialized again?
this is parent structure, and mentioned component is rendered withing router-outled
<div id="content">
<live-sidebar-component></live-sidebar-component>
<div id="page-wrapper">
<live-breadcrumbs></live-breadcrumbs>
<div id="page">
<router-outlet></router-outlet>
</div>
</div>
<div id="promobar">
<ticket-component></ticket-component>
</div>
</div>
There are plans to bring support for canReuse
.
See https://github.com/angular/angular/issues/7757#issuecomment-236737846 for more details.
As a workaround you can subscribe to params changes and do the cleanup there instead:
constructor(public route: ActivatedRoute) {
this.params = this.route.params.subscribe(
params => {
// do cleanup
console.log(params['someParam']);
}
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With