How to reload a page in angular2.
While searching through net, i got a code "this._router.renavigate()"
to reload the page but looks like its not working with latest release of angular2.
Another way is 'window.location.reload()'
but this is not the angular way of doing it.
If you really want to reload the page you need to run location.reload() outside the angular zone
this.zone.runOutsideAngular(() => {
location.reload();
});
tested with RC6
Full Example
import { Component, NgZone } from "@angular/core";
@Component({
templateUrl: "template.html"
})
export class ReloadComponent{
constructor(
private zone: NgZone) {
}
reloadPage() { // click handler or similar
this.zone.runOutsideAngular(() => {
location.reload();
});
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With