离子3-如何使用Cordova插件存储库



我试图在我的ionic3应用中使用此插件:

https://github.com/virtuoworks/canvascameraplugin

我设法安装了插件:

cordova plugin add https://github.com/VirtuoWorks/CanvasCameraPlugin.git && cordova prepare

我的问题是下一步要做什么,我需要将插件包含在应用中,使用离子本机插件可以这样完成:

import { SplashScreen } from '@ionic-native/splash-screen';

但是我应该为Canvascamera插件使用什么?

import { CanvasCamera } from '??????';

我当前的代码:

declare let CanvasCamera: any;
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Platform } from 'ionic-angular';
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  constructor(public navCtrl: NavController, public platform: Platform) {
    this.canvasCameraStart();
  }
  canvasCameraStart() {
    this.platform.ready().then(() => {
      var options = {
        quality: 75,
        destinationType: CanvasCamera.DestinationType.DATA_URL,
        encodingType: CanvasCamera.EncodingType.JPEG,
        width: 640,
        height: 480
    };
      CanvasCamera.start(options);// here call the plugin's method
    });
 }
}

您需要声明插件的对象,如下所示。

declare let CanvasCamera: any;
@Component({
  ...
})
export class TestPage {
  ...
  myPluginMethod() {
     this.platform.ready().then(() => {
       CanvasCamera.start(options);// here call the plugin's method
     });
  }
}

更新:您需要如下所示。

constructor(public navCtrl: NavController, public platform: Platform) {
 this.platform.ready().then(() => {
    this.canvasCameraStart();
   });
 }
  canvasCameraStart() {
     let options = {
        quality: 75,
        destinationType: CanvasCamera.DestinationType.DATA_URL,
        encodingType: CanvasCamera.EncodingType.JPEG,
        width: 640,
        height: 480
    };
      CanvasCamera.start(options);// here call the plugin's method
   }

此模块的贡献者为该模块制作了一个类型的定义文件,如Angular 2支持#8中所述。

您可以按照NPM @type/cordova-plugin-canvascamera上的说明安装类型定义文件。

然后,您应该能够根据Typescript 2.0在TS文件中使用Canvascamera。tsconfig.json

中的"类型"字段

最好的问候。

最新更新