Last active
September 24, 2018 18:12
-
-
Save arn-ob/1f5018aea04936627b65e7929e48b6ed to your computer and use it in GitHub Desktop.
CanDeactivate interface code
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 characters
| import { Injectable, Component } from '@angular/core'; | |
| import { CanDeactivate } from '@angular/router'; | |
| import { Observable } from 'rxjs/Observable'; | |
| export interface CanComponentDeactivate { | |
| canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean; | |
| } | |
| @Injectable() | |
| export class GurdGuard implements CanDeactivate<CanComponentDeactivate> { | |
| canDeactivate(component: CanComponentDeactivate) { | |
| return component.canDeactivate ? component.canDeactivate() : true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment