Edited at

ionicでcordova pluginをそのまま使う(non-native)

More than 1 year has passed since last update.


あらすじ

https://github.com/pwlin/cordova-plugin-file-opener2showOpenWithDialog()を使いたかったが

ionic-native化されてるやつ( https://ionicframework.com/docs/native/file-opener/ )にはメソッドが無かった :scream: ので調べた


やり方

declare const cordova; を書くだけ

イカのように使う :octopus:

import { Component } from '@angular/core';

import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { File } from '@ionic-native/file';

declare const cordova;

@IonicPage()
@Component({
selector: 'page-hoge',
templateUrl: 'hoge.html',
})
export class HogePage {

constructor(private navCtrl: NavController, private navParams: NavParams, private file: File) {
}

openFile() {
const filename = this.file.dataDirectory + 'hoge.pdf';
const mimeType = 'application/pdf';
cordova.plugins.fileOpener2.showOpenWithDialog(filename, mimeType)
}

}


まとめ

バッドノウハウ(笑)