问题
How can I reload the current page on Angular via TypeScript?
I don't want to change the URL parameters, only to reload.
回答1:
This should technically be achievable using window.location.reload()
:
HTML:
<button (click)="refresh()">Refresh</button>
TS:
refresh(): void {
window.location.reload();
}
Update:
Here is a basic StackBlitz example showing the refresh in action. Notice the URL on "/hello" path is retained when window.location.reload()
is executed.
Hopefully that helps!
来源:https://stackoverflow.com/questions/43985752/how-to-reload-page-the-whole-page-in-angular-2