How to Refresh a Component in Angular

Sreehari Ballampalli picture Sreehari Ballampalli · Dec 14, 2017 · Viewed 316.7k times · Source

I am working on an Angular project. I'm struggling with refresh action in a component.

I would like to refresh the router's components on button click. I have refresh button when I click on it the component/router need to be refresh.

I tried window.location.reload() and location.reload() these two are not suitable for my need. Please help if anyone aware of it.

Answer

Sreehari Ballampalli picture Sreehari Ballampalli · Dec 18, 2017

After some research and modifying my code as below, the script worked for me. I just added the condition:

this.router.navigateByUrl('/RefreshComponent', { skipLocationChange: true }).then(() => {
    this.router.navigate(['Your actualComponent']);
});