angular reload current page code example
Example 1: how to refresh page angular
refresh(): void {
window.location.reload();
}
Example 2: refresh current component angular
reloadCurrentRoute() {
let currentUrl = this._router.url;
this._router.navigateByUrl('/', {skipLocationChange: true}).then(() => {
this._router.navigate([currentUrl]);
console.log(currentUrl);
});
}
Example 3: angular typescript refresh page
this.router.routeReuseStrategy.shouldReuseRoute = function(){
return false;
};
this.router.events.subscribe((evt) => {
if (evt instanceof NavigationEnd) {
this.router.navigated = false;
window.scrollTo(0, 0);
}
});
Example 4: angular 6 reload current page
import { DOCUMENT } from '@angular/common';
import { Component, Inject } from '@angular/core';
@Component({
selector: 'app-refresh-banner-notification',
templateUrl: './refresh-banner-notification.component.html',
styleUrls: ['./refresh-banner-notification.component.scss']
})
export class RefreshBannerNotificationComponent {
constructor(
@Inject(DOCUMENT) private _document: Document
) {}
refreshPage() {
this._document.defaultView.location.reload();
}
}