Я использую NgbModal.Когда я нажимаю x или close, который вызывает this.activeModal.close () или this.activeModal.dismiss (), он выдает мне эту ошибку:
ReportProblemDialogComponent_Host.ngfactory.js? [sm]:1 ERROR TypeError: Cannot read property 'removeChild' of null
at NgbModalRef._removeModalElements (modal-ref.js?5ad7:114)
at NgbModalRef.dismiss (modal-ref.js?5ad7:108)
at NgbActiveModal.activeModal.dismiss (modal-stack.js?0971:36)
at ReportProblemDialogComponent.ngOnDestroy (report-problem-dialog.component.ts?631e:150)
at callProviderLifecycles (core.js?593e:12697)
at callElementProvidersLifecycles (core.js?593e:12658)
at callLifecycleHooksChildrenFirst (core.js?593e:12641)
at destroyView (core.js?593e:14007)
at callWithDebugContext (core.js?593e:15041)
at Object.debugDestroyView [as destroyView] (core.js?593e:14592)
После перезагрузки компонента он остается открытым и после перенаправленияна другую страницу, он показывает.Как закрыть NgbModal?
Это мой сервис для модального открытия:
open(component: Component): Promise<NgbModalRef> {
return new Promise<NgbModalRef>((resolve, reject) => {
const isOpen = this.ngbModalRef !== null;
if (isOpen) {
resolve(this.ngbModalRef);
}
// setTimeout used as a workaround for getting ExpressionChangedAfterItHasBeenCheckedError
setTimeout(() => {
this.ngbModalRef = this.reportProblemModalRef(component, new Object());
resolve(this.ngbModalRef);
}, 0);
});
}
reportProblemModalRef(component: Component, ticket: any): NgbModalRef {
const modalRef = this.modalService.open(component, { size: 'lg', backdrop: 'static'});
modalRef.componentInstance.ticket = ticket;
modalRef.result.then((result) => {
this.router.navigate([{ outlets: { popup: null }}], { replaceUrl: true, queryParamsHandling: 'merge' });
this.ngbModalRef = null;
}, (reason) => {
this.router.navigate([{ outlets: { popup: null }}], { replaceUrl: true, queryParamsHandling: 'merge' });
this.ngbModalRef = null;
});
return modalRef;
}