brandonroberts / vladivostok-sample

1 stars 0 forks source link

Bug: router not listening to async CanDeactivate #9

Open wardbell opened 8 years ago

wardbell commented 8 years ago

See #7.

Not working for promises or observables

Neither of these implementations will stop a navigation

import { Injectable } from '@angular/core';
import { CanDeactivate } from '@angular/router';
import { CrisisDetailComponent } from './crisis-detail.component';

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/observable/throw';

@Injectable()
export class CanDeactivateCrisisDetail implements CanDeactivate<CrisisDetailComponent> {
  constructor(private dialog: DialogService) {}

  canDeactivate(component: CrisisDetailComponent): Observable<boolean> | boolean {
    return Observable.of(false);       // doesn't work
    return Observable.throw(false); // neither does this.
  }
}