1reloadComponent() {
2 let currentUrl = this.router.url;
3 this.router.routeReuseStrategy.shouldReuseRoute = () => false;
4 this.router.onSameUrlNavigation = 'reload';
5 this.router.navigate([currentUrl]);
6 }
1reloadCurrentRoute() {
2 let currentUrl = this.router.url;
3 this.router.navigateByUrl('/', {skipLocationChange: true}).then(() => {
4 this.router.navigate([currentUrl]);
5 });
6}
7
1 reloadCurrentRoute() {
2 let currentUrl = this._router.url;
3 this._router.navigateByUrl('/', {skipLocationChange: true}).then(() => {
4 this._router.navigate([currentUrl]);
5 console.log(currentUrl);
6 });
7 }
1this.router.navigateByUrl('/RefreshComponent', { skipLocationChange: true }).then(() => {
2 this.router.navigate(['Your actualComponent']);
3});
1DeleteEmployee(id:number)
2 {
3 this.employeeService.deleteEmployee(id)
4 .subscribe(
5 (data) =>{
6 console.log(data);
7 this.ngOnInit();
8 }),
9 err => {
10 console.log("Error");
11 }
12 }
13
1/*You can use a BehaviorSubject for communicating between different
2components throughout the app.
3You can define a data sharing service containing the BehaviorSubject to
4which you can subscribe and emit changes.
5
6Define a data sharing service
7*/
8
9import { Injectable } from '@angular/core';
10import { BehaviorSubject } from 'rxjs';
11
12@Injectable()
13export class DataSharingService {
14 public isUserLoggedIn: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
15}
16
17/*Add the DataSharingService in your AppModule providers entry.
18
19Next, import the DataSharingService in your <app-header> and in the
20component where you perform the sign-in operation. In <app-header>
21subscribe to the changes to isUserLoggedIn subject:
22*/
23
24import { DataSharingService } from './data-sharing.service';
25
26export class AppHeaderComponent {
27 // Define a variable to use for showing/hiding the Login button
28 isUserLoggedIn: boolean;
29
30 constructor(private dataSharingService: DataSharingService) {
31
32 // Subscribe here, this will automatically update
33 // "isUserLoggedIn" whenever a change to the subject is made.
34 this.dataSharingService.isUserLoggedIn.subscribe( value => {
35 this.isUserLoggedIn = value;
36 });
37 }
38}
39
40/*In your <app-header> html template, you need to add the *ngIf
41condition e.g.:
42*/
43
44<button *ngIf="!isUserLoggedIn">Login</button>
45<button *ngIf="isUserLoggedIn">Sign Out</button>
46
47// Finally, you just need to emit the event once the user has logged in e.g:
48
49someMethodThatPerformsUserLogin() {
50 // Some code
51 // .....
52 // After the user has logged in, emit the behavior subject changes.
53 this.dataSharingService.isUserLoggedIn.next(true);
54}