尝试从 ionic 2 应用程序中的 url 打开 pdf 文件打开器 2 插件不起作用
执行的步骤: 1. 生成的应用程序使用:
ionic start fileopener blank --v2
Run Code Online (Sandbox Code Playgroud)
2.新增文件开启器:
sudo cordova plugin add cordova-plugin-file-opener2
Run Code Online (Sandbox Code Playgroud)
sudo npm install --save @ionic-native/file-opener
import { Component } from '@angular/core';
import { FileOpener } from '@ionic-native/file-opener';
@Component({
selector: 'page-home',
template: ` <ion-content>
<button ion-button (click)="viewPdf()">Download pdf</button>
</ion-content>
`
})
export class HomePage {
constructor(private fileOpener: FileOpener) { }
viewPdf(path) {
this.fileOpener.open('assets/my.pdf', 'application/pdf')
.then(() => alert('File is opened'))
.catch(e =>alert(e));
}
}
Run Code Online (Sandbox Code Playgroud)
import …Run Code Online (Sandbox Code Playgroud)