in Angular I want to refresh one component from another component.
I saw this article
https://medium.com/@rakshitshah/refresh-angular-component-without-navigation-148a87c2de3f
which suggest to add
mySubscription: any;
Then to add following in the constructor of my component.
this.router.routeReuseStrategy.shouldReuseRoute = function () {
return false;
};
this.mySubscription = this.router.events.subscribe((event) => {
if (event instanceof NavigationEnd) {
// Trick the Router into believing it's last link wasn't previously loaded
this.router.navigated = false;
}
});
And make sure to unsubscribe to "mySubscription" like below
ngOnDestroy() {
if (this.mySubscription) {
this.mySubscription.unsubscribe();
}
}
but I don't understand it because there is no information about in which component should I add this, and how to trigger the refresh on button click event.. If someone can help I will be so grateful !
Bif you click a button on componentA? If yes, then why you need to refresh it - Kalhan.Toress