Skip to content

Instantly share code, notes, and snippets.

@arn-ob
Last active September 24, 2018 18:12
Show Gist options
  • Select an option

  • Save arn-ob/1f5018aea04936627b65e7929e48b6ed to your computer and use it in GitHub Desktop.

Select an option

Save arn-ob/1f5018aea04936627b65e7929e48b6ed to your computer and use it in GitHub Desktop.
CanDeactivate interface code
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