i am working in project where using model to show PDFTron webviewer. i am using model popup to load webviewer inside it when select pdf file from list.
first time it loads pdf document but when "clr-modal" open second time webviewer not load document.
//PdfviewerComponent html.
<div class="page">
<div #viewer class="viewer"></div>
</div>
export class PdfviewerComponent implements OnInit, AfterViewInit, OnChanges {
@ViewChild('viewer', { static: true }) viewer: ElementRef;
@Input() hash: string;
wvInstance: any;
constructor() { }
ngOnInit(): void { }
ngAfterViewInit(): void {
console.log('AfterViewInit called');
WebViewer({
path: '../assets/lib'
}, this.viewer.nativeElement).then(instance => {
this.wvInstance = instance;
const idtoken = localStorage.getItem('id_token');
const options = {
customHeaders: { Authorization: 'Bearer ' + idtoken }
};
const hash = this.hash.split(' ')[0];
const url = `/api/project/readfile/${hash}`;
this.wvInstance.loadDocument(url, options);
});
}
}
//popup in main component
<clr-modal [(clrModalOpen)]="openModel" >
<h3 class="modal-title">{{currentFileName}}</h3>
<div class="modal-body">
<app-pdfviewer [hash]="currentFileHash"></app-pdfviewer>
</div>
</clr-modal>