-
-
Save pazel-io/965bb3a9463c1860d3ba8578818f4c34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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