Error on closing modal with content ngx-extended-pdf-viewer

372 Views Asked by At

I am calling a pdf document using ngx-extended-pdf-viewer in angular everything works fine until I close the modal. I get the following error

ERROR TypeError: Cannot read properties of null (reading 'removeEventListener')
    at Object.unbindWindowEvents (viewer-3.5.531.min.js:44:33497)
    at ngx-extended-pdf-viewer.mjs:4133:46
    at timer (zone.js:2405:41)
    at _ZoneDelegate.invokeTask (zone.js:406:31)
    at Object.onInvokeTask (core.mjs:26237:33)
    at _ZoneDelegate.invokeTask (zone.js:405:60)
    at Zone.runTask (zone.js:178:47)
    at invokeTask (zone.js:487:34)
    at ZoneTask.invoke (zone.js:476:48)
    at data.args.<computed> (zone.js:2385:32)

I tried to create a function while closing the modal in order to unsubscribe from pdf functionality.

 Modaldismiss(){
    if (this.pdfViewerSubscription) {
      this.pdfViewerSubscription.unsubscribe();
      this.pdfViewerSubscription = null;
    }
    this.modalService.dismissAll();
      // Unsubscribe from the PDF viewer subscription
  }

And calling it into my html file with the following code

<ng-template #pdfModal let-modal>
              <div class="modal-header">
                <h5>Χώρα: <br />{{ file.countryName }}</h5>
                <h5 class="modal-title" id="pdfModalLabel">
                  Όνομα Αρχείου: <br />{{ file.certName }}
                </h5>
                <button
                  mat-mini-fab
                  color="warn"
                  class="close"
                  aria-label="Close"
                  (click)="Modaldismiss()"
                >
                  <span aria-hidden="true">&times;</span>
                </button>
              </div>
              <div class="modal-body">
                <ngx-extended-pdf-viewer
                  [src]="previewUrl"
                  [height]="'900px'"
                  [useBrowserLocale]="true"
                  [textLayer]="true"
                  [showHandToolButton]="true"
                >
                  ></ngx-extended-pdf-viewer
                >
              </div>
              <div class="modal-footer">
                <button
                  type="button"
                  mat-flat-button
                  color="warn"
                  (click)="Modaldismiss()"
                >
                  Close
                </button>
              </div>
            </ng-template>

but this did not work too.

Any ideas from where to start I would be grateful.

Thank you in advance,

Nick

0

There are 0 best solutions below