title: Why is NgbModal throwing error on close/dismiss?
body: <p>I am using NgbModal. When I click x or close, which calls this.activeModal.close() or this.activeModal.dismiss() it throws me this error:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>After reloading component, it still stays open and after redirection to another page, it is showing. How to close NgbModal?</p>
  
  <p>This is my service for opening modal:</p>
  
  <pre><code>open(component: Component): Promise&lt;NgbModalRef&gt; {
  
      return new Promise&lt;NgbModalRef&gt;((resolve, reject) =&gt; {
          const isOpen = this.ngbModalRef !== null;
          if (isOpen) {
              resolve(this.ngbModalRef);
          }
          // setTimeout used as a workaround for getting ExpressionChangedAfterItHasBeenCheckedError
          setTimeout(() =&gt; {
              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) =&gt; {
          this.router.navigate([{ outlets: { popup: null }}], { replaceUrl: true, queryParamsHandling: 'merge' });
          this.ngbModalRef = null;
      }, (reason) =&gt; {
          this.router.navigate([{ outlets: { popup: null }}], { replaceUrl: true, queryParamsHandling: 'merge' });
          this.ngbModalRef = null;
      });
      return modalRef;
  }
  </code></pre>