how to refresh page in angular 2 how to refresh page in angular 2 angular angular

how to refresh page in angular 2


If you want to reload the page , you can easily go to your component then do :

location.reload();


Just in case someone else encounters this problem. You need to call

window.location.reload()

And you cannot call this from a expression. If you want to call this from a click event you need to put this on a function:

(click)="realodPage()"

And simply define the function:

reloadPage() {   window.location.reload();}

If you are changing the route, it might not work because the click event seems to happen before the route changes. A very dirty solution is just to add a small delay

reloadPage() {    setTimeout(()=>{      window.location.reload();    }, 100);}


Updated

How to implement page refresh in Angular 2+ note this is done within your component:

location.reload();