Skip to content

Instantly share code, notes, and snippets.

@pazel-io
Last active October 18, 2020 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pazel-io/965bb3a9463c1860d3ba8578818f4c34 to your computer and use it in GitHub Desktop.
Save pazel-io/965bb3a9463c1860d3ba8578818f4c34 to your computer and use it in GitHub Desktop.
import { Component, OnDestroy, OnInit } from '@angular/core';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { ModalComponent } from './modal/modal.component';
import { take } from 'rxjs/operators';
import { Router } from '@angular/router';
@Component({
selector: 'app-modal-wrapper',
template: '',
})
export class ModalWrapperComponent implements OnInit, OnDestroy {
private dialogRef: MatDialogRef<ModalComponent>;
private closedOnDestroy = false;
constructor(private dialog: MatDialog,
private router: Router,
) {
}
ngOnInit(): void {
this.openDialog();
}
private openDialog(): void {
this.dialogRef = this.dialog.open(ModalComponent,
{
minWidth: '700px',
minHeight: '400px'
});
this.dialogRef.afterClosed()
.pipe(take(1))
.subscribe(result => {
if (this.closedOnDestroy) {
return;
}
return this.router.navigate(['map']);
});
}
public ngOnDestroy(): void {
this.closedOnDestroy = true;
this.dialogRef.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment