summaryrefslogtreecommitdiffstats
path: root/cds-ui/designer-client/src/app/common/core/canDactivate/ComponentCanDeactivateGuard.ts
blob: b24784262d634c327f1c74c5e66be1d0734f785c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import {Injectable} from '@angular/core';

import {CanDeactivate} from '@angular/router';
import {ComponentCanDeactivate} from './ComponentCanDeactivate';

@Injectable()
export class ComponentCanDeactivateGuard implements CanDeactivate<ComponentCanDeactivate> {
    canDeactivate(component: ComponentCanDeactivate): boolean {

        if (component.canDeactivate()) {
            if (confirm('You have unsaved changes! If you leave, your changes will be lost.')) {
                return true;
            } else {
                return false;
            }
        }
        return true;
    }
}