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