[英]Issue at using cordova camera plugin within angular2
我嘗試使用 angular2 中的一個簡單測試組件來運行 cordova-plugin-camera。
首先,我通過在cordova 上安裝插件將插件添加到cordova。 接下來,我在 index.html 中添加了cordova.js。
<body>
<app-root>Loading...</app-root>
<script type="text/javascript" src="cordova.js"></script>
</body>
之后,我構建了一個簡單的 angular 組件來調用cordova 插件。 這個組件有一個按鈕,這個按鈕應該通過cordova調用原生相機。
Componenten HTML
<p>
testcamera works!
</p>
<div>
<button md-raised-button (click)="takePicture()">Picture</button>
</div>
通過單擊組件上的方法/函數將被調用。 我聲明了一個cordova變量來訪問cordova插件。
角分量 TS
import { Component, OnInit } from '@angular/core';
declare let cordova: any;
@Component({
selector: 'app-testcamera',
templateUrl: './testcamera.component.html',
styleUrls: ['./testcamera.component.css']
})
export class TestcameraComponent implements OnInit {
public base64Image : String;
public photos;
public text;
constructor() {
}
ngOnInit() {
}
takePicture(){
cordova.plugins.camera.getPicture({
destinationType: cordova.plugins.camera.DestinationType.DATA_URL,
targetWidth: 1000,
targetHeight: 1000
}).then((imageData) => {
// imageData is a base64 encoded string
this.base64Image = "data:image/jpeg;base64," + imageData;
}, (err) => {
console.log(err);
});
}
}
該組件可以正常工作,但是當我按下“圖片”按鈕時,該函數會被調用,但cordova 不會打開本機圖片應用程序。 調用cordova.plugins.camera.getPicture(..) 不起作用。 任何人都可以幫忙嗎? 我錯過了什么? 非常感謝。
好吧,我幫助自己。 我遇到的問題是我選擇了錯誤的變量。
而不是
目的地類型:cordova.plugins.camera.DestinationType.DATA_URL,
我補充一下:
目的地類型:navigator.camera.DestinationType.DATA_URL,
同樣為此,我必須為它聲明一個變量。
聲明讓導航器:任何;`
非常感謝`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.