Posts

Showing posts from May, 2020

Refresh an Angular Component without reloading the same Component

Image
A short trick for refreshing data in the same Angular components. This snippet will work in Angular 2, 4, 5, 6, 7, 8, and 9. Here two method and  you can add according to your needs you are working with Angular and need to refresh a component without navigation on another component without  using   window.location.reload()    or   location.reload() ,  you can use the following code in your project: 1. using constructor in the same page(component) reload: 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 ;   } }); Make sure to ...