2017-09-13 51 views
1

我試着在我Ionic3應用程序使用這個插件:Ionic 3 - 如何使用cordova插件回購?

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

} 

回答

1

需要聲明插件的對象,如下圖所示。

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 
    } 
+0

感謝您的回覆! 我在哪裏添加聲明行?如果我將它添加到「進口」下面的行中,我會得到一個TS錯誤「[ts]」,「預計」。 – Sultanen

+0

確定只是做到這一點,讓我知道:'聲明讓CanvasCamera:任何;' – Sampath

+0

這工作正常:)我更新到您提供的代碼,現在我得到一個運行時錯誤「運行時錯誤 未捕獲(承諾):ReferenceError: CanvasCamera沒有定義ReferenceError:CanvasCamera沒有在http:// localhost:8123/build/main.js:66:34上定義在t.invoke「 – Sultanen