Skip to content

Commit

Permalink
Close the lightbox when the active route is changed, closes #108
Browse files Browse the repository at this point in the history
  • Loading branch information
MurhafSousli committed Jul 3, 2018
1 parent 82cec23 commit d099abd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion projects/lightbox/src/lib/lightbox.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component, HostBinding, HostListener, ChangeDetectionStrategy } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { Router, RouterEvent, NavigationStart } from '@angular/router';
import { OverlayRef } from '@angular/cdk/overlay';
import { filter, tap, take } from 'rxjs/operators';
import { lightboxAnimations } from './lightbox.animation';

@Component({
Expand Down Expand Up @@ -35,7 +37,13 @@ export class LightboxComponent {
}
}

constructor(public sanitizer: DomSanitizer) {
constructor(public sanitizer: DomSanitizer, router: Router) {
// Close the lightbox if the current route has changed
router.events.pipe(
filter((event: RouterEvent) => event instanceof NavigationStart),
tap(() => this.overlayRef.detach()),
take(1)
).subscribe();
}

}
2 changes: 2 additions & 0 deletions projects/lightbox/src/lib/lightbox.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NgModule, ModuleWithProviders } from '@angular/core';
import { RouterModule } from '@angular/router';
import { Overlay, OverlayModule } from '@angular/cdk/overlay';
import { Gallery, GalleryModule } from '@ngx-gallery/core';

Expand All @@ -13,6 +14,7 @@ export function lightboxFactory(config: LightboxConfig, gallery: Gallery, overla

@NgModule({
imports: [
RouterModule,
OverlayModule,
GalleryModule
],
Expand Down

0 comments on commit d099abd

Please sign in to comment.