intbot / ng2-pdfjs-viewer

An angular component for PDFJS and ViewerJS (Supports all versions of angular)
Apache License 2.0
225 stars 113 forks source link

onDocumentLoad does not fire when the viewer is hidden #167

Closed anees-tricon closed 2 years ago

anees-tricon commented 2 years ago

I am trying to do a simple show hide use case. i will show a loading icon and hide the pdfjs viewer initially and in onDocumentLoad i toggle the boolean so that the loader goes away and the pdf is visible.

What i observe is, if the pdfjs viewer is hidden, the event does not trigger. Is that by design?

<div class="pdf-container" [hidden]="isLoading">
      <ng2-pdfjs-viewer
        #pdfViewer
        [showSpinner]="true"
        [openFile]="false"
        [download]="true"
        [print]="true"
        [viewBookmark]="false"
        viewerId="document"
        (onDocumentLoad)="loadComplete()"
        pagemode="none"
      >
      </ng2-pdfjs-viewer>
</div>
<div class="pdf-container" [class.hide]="isLoading"> 
      <ng2-pdfjs-viewer
        #pdfViewer
        [showSpinner]="true"
        [openFile]="false"
        [download]="true"
        [print]="true"
        [viewBookmark]="false"
        viewerId="document"
        (onDocumentLoad)="loadComplete()"
        pagemode="none"
      >
      </ng2-pdfjs-viewer>
</div>
//css file
.hide {
  display: none;
}
// component ts
loadComplete() {
  this.isLoading = false;
}

Even if its hidden via the parent using [hidden] or by css the event is not getting triggered.

anees-tricon commented 2 years ago

It works though if i use visibilty:hidden

<div class="pdf-container" [class.invisible]="isLoading"> 
      <ng2-pdfjs-viewer
        #pdfViewer
        [showSpinner]="true"
        [openFile]="false"
        [download]="true"
        [print]="true"
        [viewBookmark]="false"
        viewerId="document"
        (onDocumentLoad)="loadComplete()"
        pagemode="none"
      >
      </ng2-pdfjs-viewer>
</div>
// css
.invisible {
  visibility: hidden
}
codehippie1 commented 2 years ago

Closing as the user achieved desired outcome