Skip to content

Commit

Permalink
fix: (core) make router in dialog optional (#3360)
Browse files Browse the repository at this point in the history
  • Loading branch information
reinholdk committed Sep 24, 2020
1 parent 920003a commit f2fa015
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
7 changes: 7 additions & 0 deletions libs/core/src/lib/dialog/dialog.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ describe('DialogComponent', () => {
expect(dialogComponent).toBeTruthy();
});

it('should create w/o Router', () => {
setup([{ token: Router, provider: { useValue: null } }]);
expect(router).toBeNull();
expect(component).toBeTruthy();
expect(dialogComponent).toBeTruthy();
});

it('should hide dialog', () => {
setup();

Expand Down
20 changes: 11 additions & 9 deletions libs/core/src/lib/dialog/dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ export class DialogComponent implements OnInit, AfterViewInit, OnDestroy, CssCla
@Optional() @Inject(DIALOG_REF) private _dialogRef: DialogRef,
private _elementRef: ElementRef,
private _changeDetectorRef: ChangeDetectorRef,
private _router: Router
) {}
@Optional() private _router?: Router
) { }

/** @hidden */
ngOnInit(): void {
Expand Down Expand Up @@ -250,12 +250,14 @@ export class DialogComponent implements OnInit, AfterViewInit, OnDestroy, CssCla

/** @hidden Subscribes to router navigation for the closing of dialog on navigation start. */
private _subscribeToNavigation(): void {
this._subscriptions.add(
this._router.events.subscribe(event => {
if (event instanceof NavigationStart && this.dialogConfig.closeOnNavigation) {
this._dialogRef.dismiss();
}
})
);
if (this._router) {
this._subscriptions.add(
this._router.events.subscribe(event => {
if (event instanceof NavigationStart && this.dialogConfig.closeOnNavigation) {
this._dialogRef.dismiss();
}
})
);
}
}
}

0 comments on commit f2fa015

Please sign in to comment.