Ionic framework ionic对象(…)不是DocumentViewer上的函数。viewDocument:
我正在尝试从爱奥尼亚的资产文件夹加载pdf或下载一个。我看过一些教程,但都给了我同样的错误 离子型:Ionic framework ionic对象(…)不是DocumentViewer上的函数。viewDocument:,ionic-framework,Ionic Framework,我正在尝试从爱奥尼亚的资产文件夹加载pdf或下载一个。我看过一些教程,但都给了我同样的错误 离子型: 爱奥尼亚(爱奥尼亚CLI):4.1.2(C:\Users\hanna\node\u modules\爱奥尼亚) 离子骨架:离子角3.9.3 @爱奥尼亚/应用程序脚本:3.2.1 科尔多瓦: cordova(cordova CLI):8.1.2(cordova-lib@8.1.1) Cordova平台:android 6.4.0,浏览器5.0.4 Cordova插件:Cordova插件ion
- 爱奥尼亚(爱奥尼亚CLI):4.1.2(C:\Users\hanna\node\u modules\爱奥尼亚)
- 离子骨架:离子角3.9.3
- @爱奥尼亚/应用程序脚本:3.2.1
- cordova(cordova CLI):8.1.2(cordova-lib@8.1.1)
- Cordova平台:android 6.4.0,浏览器5.0.4
- Cordova插件:Cordova插件ionic键盘2.1.3、Cordova插件ionic webview 3.1.2(和7个其他插件)
- NodeJS:v9.4.0(C:\Program Files\NodeJS\node.exe)
- 净现值:5.6.0
- 操作系统:Windows 10
import { Component } from '@angular/core';
import { DocumentViewer, DocumentViewerOptions } from '@ionic-
native/document-viewer/ngx';
import { FileOpener } from '@ionic-native/file-opener/ngx';
import { FileTransfer } from '@ionic-native/file-transfer/ngx';
import { File } from '@ionic-native/File/ngx';
import { NavController, Platform } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(
public navCtrl: NavController,
private file: File,
private ft: FileTransfer,
private document: DocumentViewer,
public platform: Platform
) {}
openLocalPdf() {
// let filePath = this.file.applicationDirectory + 'www/assets';
// if (this.platform.is('android') || this.platform.is('browser')) {
// let fakeName = Date.now();
// this.file.copyFile(filePath, 'Typescript_Jumpstart_Book_Udemy.pdf', this.file.dataDirectory, `${fakeName}.pdf`).then(result => {
// this.fileOpener.open(result.nativeURL, 'application/pdf')
// .then(() => console.log('File is opened'))
// .catch(e => console.log('Error opening file', e));
// })
// } else {
// // Use Document viewer for iOS for a better UI
// const options: DocumentViewerOptions = {
// title: 'My PDF'
// }
// this.document.viewDocument(`${filePath}/5-tools.pdf`, 'application/pdf', options);
// }
console.log('Documents Pressed.....');
const options: DocumentViewerOptions = {
title: "My PDF"
}
this.document.viewDocument('assets/Typescript_Jumpstart_Book_Udemy.pdf', 'application/pdf', options)
console.log('Documents Pressed..... afterrr');
}
downloadAndOpenPdf() {
let path = null;
if (this.platform.is('ios')) {
path = this.file.documentsDirectory;
} else {
path = this.file.dataDirectory;
}
const transfer = this.ft.create();
transfer.download('https://devdactic.com/html/5-simple-hacks-LBT.pdf', path + 'MyFile.pdf').then(entry => {
let url = entry.toURL();
this.document.viewDocument(url, 'application/pdf', {});
// this.fileOpener.open(url, 'application/pdf')
// .then(() => console.log('File is opened'))
// .catch(e => console.log('Error opening file', e));
});
}
}
错误是:
ERROR TypeError: Object(...) is not a function
at DocumentViewer.viewDocument (index.js:29)
at HomePage.webpackJsonp.193.HomePage.openLocalPdf (home.ts:43)
at Object.eval [as handleEvent] (HomePage.html:10)
at handleEvent (core.js:13589)
at callWithDebugContext (core.js:15098)
at Object.debugHandleEvent [as handleEvent] (core.js:14685)
at dispatchEvent (core.js:10004)
at core.js:10629
at HTMLButtonElement.<anonymous> (platform-browser.js:2628)
at t.invokeTask (polyfills.js:3)
错误类型错误:对象(…)不是函数
在DocumentViewer.viewDocument(index.js:29)
在HomePage.webpackJsonp.193.HomePage.openLocalPdf(home.ts:43)上
在Object.eval[as handleEvent](HomePage.html:10)
在handleEvent(core.js:13589)
在callWithDebugContext上(core.js:15098)
在Object.debugHandleEvent[作为handleEvent](core.js:14685)
在dispatchEvent(core.js:10004)
在core.js:10629
在HTMLButtoneElement。(platformbrowser.js:2628)
在t.invokeTask(polyfills.js:3)
您使用的是爱奥尼亚3,您使用的是爱奥尼亚4支持的插件版本。通过阅读Ionic v3文档,使用Ionic 3支持的插件
参考:
步骤1
卸载所有本机插件
步骤2
安装版本4。下面的例子
$ ionic cordova plugin add cordova-plugin-document-viewer
$ npm install --save @ionic-native/document-viewer@4
步骤3
不要在导入结束时附加ngx,它仅适用于Angular 6
import { DocumentViewer } from '@ionic-native/document-viewer';
第4步:
对其他本机插件重复第2步和第3步。是的,正确答案我面临同样的问题,我是否也需要降级ionic cli版本?