Ionic 4:我正在使用Document Viewer来查看pdf文件。但它不起作用

时间:2019-05-09 11:59:50

标签: ionic-framework ionic4

我正在尝试使用文档查看器读取新ionic 4项目中Assets文件夹中的pdf文件,但遇到错误

  

未捕获的TypeError:Object(...)不是函数       在index.js:139       在Module ../ node_modules/@ionic-native/document-viewer/index.js(index.js:190)       位于 webpack_require (引导程序:83)       在Module ../ src / app / app.module.ts(app.component.ts:11)       位于 webpack_require (引导程序:83)       在Module ../ src / main.ts(main.ts:1)       位于 webpack_require (引导程序:83)       在Object.0(main.ts:12)       位于 webpack_require (引导程序:83)       在checkDeferredModules(bootstrap:45)

contents.page.ts

import { ActivatedRoute } from '@angular/router';
import { Component, OnInit } from '@angular/core';
import { Location } from '@angular/common';
import { DocumentViewer, DocumentViewerOptions } from '@ionic-native/document-viewer';
declare var require: any;
const novels = require('../../../assets/Json/novels.json');

@Component({
  selector: 'app-contents',
  templateUrl: './contents.page.html',
  styleUrls: ['./contents.page.scss']
})

export class ContentsPage implements OnInit {
  source: string;
  bookId: any;
  slide: any;


  options: DocumentViewerOptions = {
    title: 'My PDF'
  }
  constructor(private _location: Location,private activatedRoute: ActivatedRoute,private document: DocumentViewer) {}
  goBack() {
    console.log('back');
    this._location.back();
  }
  ngOnInit() {
    this.slide = novels;
    this.bookId = this.activatedRoute.snapshot.paramMap.get('bookid');

    this.slide.forEach(obj => {
    if (obj.idNumber === this.bookId) { 
    this.document.viewDocument(this.source, 'application/pdf', this.options)
}
    });


  }


}

contents.page.html

<ion-header>
    <ion-toolbar color="success">
        <ion-icon class="iconSize" slot="start" (click)="goBack()" name="arrow-back"></ion-icon>
        <ion-title>Contents</ion-title>
        <ion-icon class="iconSize" slot="end" [routerLink]="['/home']" name="home"></ion-icon>
      </ion-toolbar>
</ion-header>

<ion-content>


</ion-content>

0 个答案:

没有答案