【ng2-pdf-viewer】Cannot read prop

2019-07-19  本文已影响0人  匿于烟火中

报错场景:在boostrap modal中使用ng2-pdf-viewer预览pdf,多次打开pdf出现报错

    <ng-template #attachPreview let-modal>
        <pdf-viewer 
        #pdfPreviwer
        [src]="previewDoc.url" 
        [render-text]="false"
        [original-size]="true"
        style="display: block;width: fit-content;" 
        >
        </pdf-viewer>
    </ng-template>

解决方案:

ng2-pdf-viewer has a dependency called pdfjs-dist. You can find it in node_modules.
Open this file -> node_modules/pdfjs-dist/web/pdf_viewer.js
In pdf_viewer.js file, search for this line of code -> var elt = views[index].div; It is inside 'backtrackBeforeAllVisibleElements' function.
Change that code line to var elt = views[index-1].div; and save.

github

上一篇下一篇

猜你喜欢

热点阅读