xxxxxxxxxx
reloadCurrentRoute() {
let currentUrl = this._router.url;
this._router.navigateByUrl('/', {skipLocationChange: true}).then(() => {
this._router.navigate([currentUrl]);
console.log(currentUrl);
});
}
xxxxxxxxxx
reloadComponent() {
let currentUrl = this.router.url;
this.router.routeReuseStrategy.shouldReuseRoute = () => false;
this.router.onSameUrlNavigation = 'reload';
this.router.navigate([currentUrl]);
}
xxxxxxxxxx
reloadCurrentRoute() {
let currentUrl = this.router.url;
this.router.navigateByUrl('/', {skipLocationChange: true}).then(() => {
this.router.navigate([currentUrl]);
});
}
xxxxxxxxxx
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-your-component',
template: `
<button (click)="refreshPage()">Refresh Page</button>
`,
})
export class YourComponent implements OnInit {
ngOnInit(): void {}
refreshPage(): void {
// Reload/refresh the current page
window.location.reload();
}
}
xxxxxxxxxx
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'refreshPage';
constructor(public _router: Router, public _location: Location) { }
refresh(): void {
this._router.navigateByUrl("/refresh", { skipLocationChange: true }).then(() => {
console.log(decodeURI(this._location.path()));
this._router.navigate([decodeURI(this._location.path())]);
});
}
}
xxxxxxxxxx
DeleteEmployee(id:number)
{
this.employeeService.deleteEmployee(id)
.subscribe(
(data) =>{
console.log(data);
this.ngOnInit();
}),
err => {
console.log("Error");
}
}