d

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.

15 St Margarets, NY 10033
(+381) 11 123 4567
ouroffice@aware.com

 

KMF

Angular Basics: Refresh an Angular Component without reloading the same Component

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

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

Make sure to unsubscribe from this mySubscription in ngOnDestroy().

Here, we just trick the router into believing that the last link was never visited; when the button is clicked, the program will load that component (refreshing the component).

This snippet will work in all Angular versions.

Credit: Source link

Previous Next
Close
Test Caption
Test Description goes like this