web-dave / angular-starter-v2

6 stars 3 forks source link

read from store #35

Open web-dave opened 7 years ago

web-dave commented 7 years ago
web-dave commented 7 years ago

leave.guard.ts

...
import { NgRedux } from '@angular-redux/store';

@Injectable()
export class LeaveGuard implements CanDeactivate<BookNewComponent> {

  constructor(private ngRedux: NgRedux<IAppState>) { }
  ...
}
web-dave commented 7 years ago

leave.guard.ts

...
  canDeactivate(target: BookNewComponent) {
    if (this.ngRedux.getState().formdirty) {
      return window.confirm('Do you really want to cancel?');
    } else {
      return true;
    }
  }
...