import { Injectable }           from '@angular/core';
import { CanDeactivate,
    ActivatedRouteSnapshot,
    RouterStateSnapshot }  from '@angular/router';
import {DocumentEditChangeMonitor} from "idai-components-2/documents";
import { ResourceEditNavigationComponent } from './resource-edit-navigation.component';
import { CanDeactivateGuardBase} from '../common/can-deactivate-guard-base';

/**
 * @author Daniel de Oliveira
 */
@Injectable()
export class ResourceEditCanDeactivateGuard
    extends CanDeactivateGuardBase
    implements CanDeactivate<ResourceEditNavigationComponent> {
    
    constructor (private documentEditChangeMonitor:DocumentEditChangeMonitor) {super();}

    canDeactivate(
        component: ResourceEditNavigationComponent,
        route: ActivatedRouteSnapshot,
        state: RouterStateSnapshot
    ): Promise<boolean> | boolean {

        return this.resolveOrShowModal(component,function() {
            if (!this.documentEditChangeMonitor.isChanged()) {
                if (component.mode=='new') {
                    component.discard(true);
                }
                return true;
            }
            return false;
        }.bind(this));
    }
}

import { Injectable }           from '@angular/core';
import { CanDeactivate,
    ActivatedRouteSnapshot,
    RouterStateSnapshot }  from '@angular/router';
import {DocumentEditChangeMonitor} from "idai-components-2/documents";
import { ResourceEditNavigationComponent } from './resource-edit-navigation.component';
import { CanDeactivateGuardBase} from '../common/can-deactivate-guard-base';

/**
 * @author Daniel de Oliveira
 */
@Injectable()
export class ResourceEditCanDeactivateGuard
    extends CanDeactivateGuardBase
    implements CanDeactivate<ResourceEditNavigationComponent> {
    
    constructor (private documentEditChangeMonitor:DocumentEditChangeMonitor) {super();}

    canDeactivate(
        component: ResourceEditNavigationComponent,
        route: ActivatedRouteSnapshot,
        state: RouterStateSnapshot
    ): Promise<boolean> | boolean {

        return this.resolveOrShowModal(component,function() {
            if (!this.documentEditChangeMonitor.isChanged()) {
                if (component.mode=='new') {
                    component.discard();
                }
                return true;
            }
            return false;
        }.bind(this));
    }
}

--- 
+++ 
@@ -25,7 +25,7 @@
         return this.resolveOrShowModal(component,function() {
             if (!this.documentEditChangeMonitor.isChanged()) {
                 if (component.mode=='new') {
-                    component.discard();
+                    component.discard(true);
                 }
                 return true;
             }
Fix bug which caused a console error got thrown in tests.
