Method close in MzModalService
Hello, i'm need of method close in MzModalService, because when a component die i need close modal a modal it's open.
exemaple:
constructor(private modalService: MzModalService) { }
ngOnDestroy() {
this.modalService.close(ModalExampleComponent);
}
Althought this is not ideal, you can still close the modal programmatically when using MzModalService by using the returned ComponentRef<MzBaseModal> object.
private modalExampleRef: ComponentRef<MzBaseModal>;
constructor(private modalService: MzModalService) { }
ngOnDestroy() {
this.closeModal();
}
openModal() {
// open modal via MzModalService and get injected modal component reference
this.modalExampleRef = this.modalService.open(ModalExampleComponent);
}
closeModal() {
// if modal reference is not undefined/null close it using modal component reference
if (this.modalExampleRef) {
this.modalExampleRef.instance.modalComponent.close();
}
}
I need too.
@Albejr for now you can use the workaround that I provided but I'll see what I can do to ease the way to close modal when using MzModalService in a near future.
I'll keep the issue open until then.
TKS, according Materializecss:
ngOnDestroy(): void {
$('#mymodal').modal('close');
}
ng2-materialize is beautiful.