-
-
Save Zephyrante/38a7d0565ff609956d1c981cff23c9d3 to your computer and use it in GitHub Desktop.
Revisions
-
Splaktar revised this gist
Jan 23, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,6 +20,7 @@ export class UnsavedChangesGuard implements CanDeactivate<CanComponentDeactivate } return Observable.create((observer: Observer<boolean>) => { // UnsavedChangesDialog defined somewhere else and imported above let dialogRef = this.dialog.open(UnsavedChangesDialog, { data: { message: 'You have unsaved changes. Are you sure you want to leave this page?' -
Splaktar revised this gist
Jan 23, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,8 +14,8 @@ export class UnsavedChangesGuard implements CanDeactivate<CanComponentDeactivate constructor(private dialog: MatDialog) {} canDeactivate(component: CanComponentDeactivate) { // Allow navigation if the component says that it is OK or it doesn't have a canDeactivate function if (!component.canDeactivate || component.canDeactivate()) { return true; } -
Splaktar revised this gist
Jan 23, 2018 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,12 +4,16 @@ import {Observable} from 'rxjs/Observable'; import {Observer} from 'rxjs/Observer'; import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material'; export interface CanComponentDeactivate { canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean; } @Injectable() export class UnsavedChangesGuard implements CanDeactivate<CanComponentDeactivate> { constructor(private dialog: MatDialog) {} canDeactivate(component: CanComponentDeactivate) { // Allow navigation if the component says that it is OK if (!component.canDeactivate()) { return true; -
Splaktar revised this gist
Jan 23, 2018 . 1 changed file with 19 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,34 +1,35 @@ import {CanDeactivate, Router} from '@angular/router'; import {Injectable} from '@angular/core'; import {Observable} from 'rxjs/Observable'; import {Observer} from 'rxjs/Observer'; import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material'; @Injectable() export class UnsavedChangesGuard implements CanDeactivate<any> { constructor(private dialog: MatDialog) {} canDeactivate(component: any) { // Allow navigation if the component says that it is OK if (!component.canDeactivate()) { return true; } return Observable.create((observer: Observer<boolean>) => { let dialogRef = this.dialog.open(UnsavedChangesDialog, { data: { message: 'You have unsaved changes. Are you sure you want to leave this page?' } }); dialogRef.afterClosed().subscribe(result => { observer.next(result); observer.complete(); }, (error) => { observer.next(false); observer.complete(); } }); }); } } -
Splaktar created this gist
Jan 23, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ import {CanDeactivate, Router} from '@angular/router'; import {Injectable} from '@angular/core'; import {ConfirmationService} from 'primeng/components/common/api'; import {FirstViewComponent} from '../first-view/first-view.component'; import {Observable} from 'rxjs/Observable'; import {Observer} from 'rxjs'; @Injectable() export class UnsavedChangesGuard implements CanDeactivate<FirstViewComponent> { constructor(private confirmationService: ConfirmationService) { } canDeactivate(component: FirstViewComponent) { // Allow navigation if the form is unchanged if (!component.dirty) { return true; } return Observable.create((observer: Observer<boolean>) => { this.confirmationService.confirm({ message: 'You have unsaved changes. Are you sure you want to leave this page?', accept: () => { observer.next(true); observer.complete(); }, reject: () => { observer.next(false); observer.complete(); } }); }); } }