We work with NG2/4 stuff. We have implemented a custom reuse strategy to perfrom the navigation from summary to details screens so we have the summary screen stay in same state (prevent it from recreation) when a user clicks back button.
The thing is that when we edit a record in a child screen and we get back to the main one we have to reload the particular data, not all entire master screen. We have to somehow infrom a component that related data has been changed and it has to update.
But in the strategy class there are no methods having access to the component. The are classes but no their instances so it is unclear how to let a component know about the particular change.
public shouldReuseRoute(future: ActivatedRouteSnapshot, current: ActivatedRouteSnapshot): boolean {
// I guess here we have to treat it somehow if it is possible
}
Had the same problem: there is a dozen of components in our application, that are being reused. Luckily all of them are inherited from one abstract class, so this solution was implemented only in one place.
Workaround is pretty ugly, but it covers the need, is very small and easy.
ngDoCheck
. ngDoCheck
callback is being called and your flag is true, set the flag to false and reload the dataconstructor(router: Router) {
super();
router.events.subscribe(e => {
if (!this._reloadData) {
this._reloadData = true;
}
});
}
private ngDoCheck() {
if (this._reloadData) {
this._reloadData = false;
this.resetData();
}
}
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