LoginSignup
2
4

More than 5 years have passed since last update.

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

Last updated at Posted at 2017-11-14

あらすじ

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)
  }

}

まとめ

バッドノウハウ(笑)

2
4
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4