A short trick for refreshing Angular components in generic way.

If you are working with Angular and need to refresh a component without navigation on another component without using window.location.reload() orlocation.reload(), you can use the following code in your project:

mySubscription: any;

Then, add this code to the required component’s constructor.

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;
  }
});

#angular-basics #angular #angular-concepts

Angular Basics: Refresh an Angular Component Without Reloading the Same Component
5.10 GEEK